Scheduler Universe: A meta-scheduler’s home

#!/usr/bin/python

#
# I'm a meta-scheduler. I submit and perform high-level
# management of jobs in a Schedd's queue. I have specialized
# knowledge that the Schedd should not have to worry itself
# about.
#
# I like to run in the Scheduler Universe with
# hold_kill_sig=SIGUSR1 and remove_kill_sig=SIGUSR2,
# e.g.
#  universe = scheduler
#  cmd = meta-scheduler.py
#  hold_kill_sig = SIGUSR1
#  remove_kill_sig = SIGUSR2
#  queue
#
# When I run in the Scheduler Universe,
#  o I run directly under the Schedd
#  o I have to carefully manage the processes I start
#  o I can get special signals in response to
#    condor_hold and condor_rm
#  o I should always exit in response to signals
#  o I should always cleanup after myself before exiting
#  o I know if I get an RM signal I'm leaving the queue
#    and may never run again
#  o I might get a HOLD signal and never an RM, if I'm
#    held and not released before I'm removed
#
# I often want to make sure I don't leave the Schedd's
# queue unless I complete successfully. To help assure
# this is the case, I can be used with on_exit_remove,
# e.g
#  on_exit_remove = ExitCode =!= UNDEFINED && ExitCode == 42
#

import signal, time, sys

running = True

def rm_handler(signum, frame):
    global running
    # Someone ran condor_rm on me!
    running = False

def hold_handler(signum, frame):
    global running
    # Someone ran condor_hold on me!
    running = False

signal.signal(signal.SIGUSR1, hold_handler)
signal.signal(signal.SIGUSR2, rm_handler)

while running:
    time.sleep(1)

sys.exit(42)
Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: