progress=run_sql("SELECT progress FROM schTASK WHERE id=%s",(_TASK_PARAMS['task_id'],))
ifprogress:
progress=progress[0][0]
else:
progress=''
g=re.match(r'Postponed (\d+) time\(s\)',progress)
ifg:
postponed_times=int(g.group(1))
else:
postponed_times=0
if_TASK_PARAMS['sequence-id']:
## Also postponing other dependent tasks.
run_sql("UPDATE schTASK SET runtime=%s, progress=%s WHERE sequenceid=%s AND status='WAITING'",(new_runtime,'Postponed as task %s'%_TASK_PARAMS['task_id'],_TASK_PARAMS['sequence-id']))# kwalitee: disable=sql
run_sql("UPDATE schTASK SET runtime=%s, status='WAITING', progress=%s, host='' WHERE id=%s",(new_runtime,'Postponed %d time(s)'%(postponed_times+1),_TASK_PARAMS['task_id']))# kwalitee: disable=sql
write_message("Task #%d postponed because outside of runtime limit"%_TASK_PARAMS['task_id'])
returnTrue
# Make sure the host field is updated
# It will not be updated properly when we run
# a task from the cli (without using the bibsched monitor)
host=bibsched_get_host(_TASK_PARAMS['task_id'])
ifhostandhost!=gethostname():
write_message("Error: The task #%d is bound to %s."%
## It has finished in a good way. We recycle the database row
run_sql("UPDATE schTASK SET runtime=%s, status='WAITING', progress=%s, host=%s WHERE id=%s",(new_runtime,verbose_argv,_TASK_PARAMS['host'],_TASK_PARAMS['task_id']))
write_message("Task #%d finished and resubmitted."%_TASK_PARAMS['task_id'])
eliftask_status=='STOPPED':
run_sql("UPDATE schTASK SET status='WAITING', progress=%s, host='' WHERE id=%s",(verbose_argv,_TASK_PARAMS['task_id'],))
write_message("Task #%d stopped and resubmitted."%_TASK_PARAMS['task_id'])
else:
## We keep the bad result and we resubmit with another id.
#res = run_sql('SELECT proc,user,sleeptime,arguments,priority FROM schTASK WHERE id=%s', (_TASK_PARAMS['task_id'], ))
sys.stderr.write(" --profile=STATS\tPrint profile information. STATS is a comma-separated\n\t\t\tlist of desired output stats (calls, cumulative,\n\t\t\tfile, line, module, name, nfl, pcalls, stdname, time).\n")
sys.stderr.write(" --stop-on-error\tIn case of unrecoverable error stop the bibsched queue.\n")
sys.stderr.write(" --continue-on-error\tIn case of unrecoverable error don't stop the bibsched queue.\n")
sys.stderr.write(" --post-process=BIB_TASKLET_NAME[parameters]\tPostprocesses the specified\n\t\t\tbibtasklet with the given parameters between square\n\t\t\tbrackets.\n")
sys.stderr.write(" --email-logs-to=EMAILS Sends an email with the results of the execution\n\t\t\tof the task, and attached the logs (EMAILS could be a comma-\n\t\t\tseparated lists of email addresses)\n")
sys.stderr.write(" --host=HOSTNAME Bind the task to the specified host, it will only ever run on that host.\n")
ifdescription:
sys.stderr.write(description)
sys.exit(exitcode)
defcb_task_sig_sleep(sig,frame):
"""Signal handler for the 'sleep' signal sent by BibSched."""
signal.signal(signal.SIGTSTP,signal.SIG_IGN)
write_message("task_sig_sleep(), got signal %s frame %s"
%(sig,frame),verbose=9)
write_message("sleeping as soon as possible...")
_db_login(relogin=1)
task_update_status("ABOUT TO SLEEP")
defcb_task_sig_stop(sig,frame):
"""Signal handler for the 'stop' signal sent by BibSched."""
write_message("task_sig_stop(), got signal %s frame %s"
%(sig,frame),verbose=9)
write_message("stopping as soon as possible...")
_db_login(relogin=1)# To avoid concurrency with an interrupted run_sql call
task_update_status("ABOUT TO STOP")
defcb_task_sig_suicide(sig,frame):
"""Signal handler for the 'suicide' signal sent by BibSched."""
write_message("task_sig_suicide(), got signal %s frame %s"
%(sig,frame),verbose=9)
write_message("suiciding myself now...")
task_update_status("SUICIDING")
write_message("suicided")
_db_login(relogin=1)
task_update_status("SUICIDED")
sys.exit(1)
defcb_task_sig_debug(sig,frame):
"""Signal handler for the 'debug' signal sent by BibSched.
This spawn a remote console server we can connect to to check
the task behavior at runtime."""
write_message("task_sig_debug(), got signal %s frame %s"
%(sig,frame),verbose=9)
fromrfoo.utilsimportrconsole
rconsole.spawn_server()
defcb_task_sig_dumb(sig,frame):
"""Dumb signal handler."""
pass
_RE_PSLINE=re.compile(r'^\s*(\w+)\s+(\w+)')
defguess_apache_process_user_from_ps():
"""Guess Apache process user by parsing the list of running processes."""
apache_users=[]
try:
# Tested on Linux, Sun and MacOS X
forlineinos.popen('ps -A -o user,comm').readlines():
g=_RE_PSLINE.match(line)
ifg:
username=g.group(1)
process=os.path.basename(g.group(2))
ifprocessin('apache','apache2','httpd'):
ifusernamenotinapache_usersandusername!='root':
apache_users.append(username)
exceptExceptionase:
print("WARNING: %s"%e,file=sys.stderr)
returntuple(apache_users)
defguess_apache_process_user():
"""
Return the possible name of the user running the Apache server process.
(Look at running OS processes or look at OS users defined in /etc/passwd.)