Disable queue when 0 pending jobs

This commit is contained in:
Jeremy Gardais 2020-09-24 14:56:27 +02:00
parent c1d23c04f6
commit e35b7af614
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 39 additions and 2 deletions

View File

@ -113,6 +113,30 @@ APT upgrade available for this system: ${RED}${local_apt_upgrade_number:=/dev/nu
return "${return_apt_upgrade_present}"
}
# }}}
is_pending_job_empty() { # {{{
## Count the number of pending jobs (qw state only)
## Excluding root's jobs
local_pending_jobs="$(qstat -s p -u '*' \
| grep --count --perl-regexp -- "(?=.*?\bqw\b)((?!root).)*$")"
case "${local_pending_jobs}" in
0 ) ## Pending jobs list is empty
return_pending_job_empty="0"
;;
* ) ## Some jobs are waiting
return_pending_job_empty="1"
;;
esac
## Simple debug message to valid current variable
debug_message "is_pending_job_empty \
Pending jobs for the compute cluster: ${RED}${local_pending_jobs:=/dev/null}${COLOR_DEBUG}."
return "${return_pending_job_empty}"
}
# }}}
main() { # {{{
@ -121,20 +145,33 @@ main() { # {{{
sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh"
## If NO APT package upgrade is available
## If NO APT package upgrade is available {{{
### Ensure to remove any temp file related to APT upgrades
### Exit
is_apt_upgrade_absent \
&& rm -f -- "${APT_TMP_FILE}" \
&& exit 0
## }}}
## If APT package upgrade is available
## If pending job list is empty AND {{{
## APT package upgrade is available
### Create a temp file
### Disable SGE queue
is_pending_job_empty \
&& is_apt_upgrade_present \
&& touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \
&& sh "${sge_disable_host_queue_script}" \
&& exit 0
## }}}
## If APT package upgrade is available {{{
### Create a temp file
### Disable SGE queue
is_apt_upgrade_present \
&& touch "${APT_TMP_FILE}" && echo "APT upgrade is available." >> "${APT_TMP_FILE}" \
&& sh "${sge_disable_host_queue_script}" \
&& exit 0
## }}}
}
# }}}