def cancel_computeset(cset): """ Sending --signal=USR1 to a running computeset job will allow it exit in the same manner as when the computeset job reaches it walltime_mins limit and is signalled by Slurm to exit. Actual poweroff of the nodes is handled by the jobscript and/or epilog. """ from api.tasks import update_computeset syslog.syslog(syslog.LOG_DEBUG, "cancel_computeset() running") cmd = ['/usr/bin/scancel', '--batch', '--quiet', '--signal=USR1', '%s' % (cset['jobid'])] try: output = check_output(cmd, stderr=STDOUT) cset["state"] = "cancelled" update_computeset.delay(cset) syslog.syslog(syslog.LOG_INFO, "Cancelling computeset job %s" % cset['name']) except OSError as e: msg = "OSError: %s" % (e) syslog.syslog(syslog.LOG_ERR, msg) except CalledProcessError as e: msg = "CalledProcessError: %s" % (e.output.strip().rstrip()) syslog.syslog(syslog.LOG_ERR, msg)
import os from api.tasks import update_computeset from nucleus.celery import * request = { 'stage': None, 'state': None, 'jobid': None, 'name': None, 'computeset': None } if os.environ.has_key('COMPUTESET_JOB_STAGE'): request['stage'] = str(os.environ['COMPUTESET_JOB_STAGE']) if os.environ.has_key('COMPUTESET_JOB_STATE'): request['state'] = str(os.environ['COMPUTESET_JOB_STATE']) if os.environ.has_key('SLURM_JOB_ID'): request['jobid'] = str(os.environ['SLURM_JOB_ID']) if os.environ.has_key('SLURM_JOB_NAME'): request['name'] = str(os.environ['SLURM_JOB_NAME']) request['id'] = int(request['name'].split('-')[2]) if os.environ.has_key('SLURM_JOB_NODELIST'): request['nodelist'] = str(os.environ['SLURM_JOB_NODELIST']) update_computeset.delay(request)
#!/usr/bin/env python import os from api.tasks import update_computeset import time from nucleus.celery import * request = {'stage': None, 'state': None, 'jobid': None, 'name': None, 'computeset': None} if os.environ.has_key('COMPUTESET_JOB_STAGE'): request['stage'] = str(os.environ['COMPUTESET_JOB_STAGE']) if os.environ.has_key('COMPUTESET_JOB_STATE'): request['state'] = str(os.environ['COMPUTESET_JOB_STATE']) if os.environ.has_key('SLURM_JOB_ID'): request['jobid'] = str(os.environ['SLURM_JOB_ID']) if os.environ.has_key('SLURM_JOB_NAME'): request['name'] = str(os.environ['SLURM_JOB_NAME']) request['id'] = int(request['name'].split('-')[2]) if os.environ.has_key('SLURM_JOB_NODELIST'): request['nodelist'] = str(os.environ['SLURM_JOB_NODELIST']) request['start_time'] = int(time.time()) update_computeset.delay(request)