1.1 --- a/imiptools/handlers/scheduling/__init__.py Mon Feb 08 00:14:53 2016 +0100
1.2 +++ b/imiptools/handlers/scheduling/__init__.py Mon Feb 08 00:47:00 2016 +0100
1.3 @@ -21,8 +21,10 @@
1.4
1.5 from imiptools.text import parse_line
1.6 from imiptools.handlers.scheduling.manifest import confirmation_functions, \
1.7 + locking_functions, \
1.8 retraction_functions, \
1.9 - scheduling_functions
1.10 + scheduling_functions, \
1.11 + unlocking_functions
1.12
1.13 # Function application/invocation.
1.14
1.15 @@ -34,12 +36,25 @@
1.16 """
1.17
1.18 # Obtain the actual scheduling functions with arguments.
1.19 + # Also obtain functions to lock resources.
1.20
1.21 - functions = get_function_calls(functions, scheduling_functions)
1.22 + schedulers = get_function_calls(functions, scheduling_functions)
1.23 + locks = get_function_calls(functions, locking_functions)
1.24 +
1.25 + # First, lock the resources to be used.
1.26 +
1.27 + for fn, args in locks:
1.28 +
1.29 + # Not all scheduling functions require compound locking.
1.30 +
1.31 + if fn:
1.32 + fn(handler, args)
1.33 +
1.34 + # Then, invoke the scheduling functions.
1.35
1.36 response = "ACCEPTED"
1.37
1.38 - for fn, args in functions:
1.39 + for fn, args in schedulers:
1.40
1.41 # NOTE: Should signal an error for incorrectly configured resources.
1.42
1.43 @@ -77,6 +92,26 @@
1.44 functions = get_function_calls(functions, confirmation_functions)
1.45 apply_functions(functions, handler)
1.46
1.47 +def finish_scheduling(functions, handler):
1.48 +
1.49 + """
1.50 + Finish scheduling using the given scheduling 'functions' for the current
1.51 + object of the given 'handler'.
1.52 + """
1.53 +
1.54 + # Obtain functions to unlock resources.
1.55 +
1.56 + locks = get_function_calls(functions, unlocking_functions)
1.57 +
1.58 + # Unlock the resources that were used.
1.59 +
1.60 + for fn, args in locks:
1.61 +
1.62 + # Not all scheduling functions require compound locking.
1.63 +
1.64 + if fn:
1.65 + fn(handler, args)
1.66 +
1.67 def retract_scheduling(functions, handler):
1.68
1.69 """