added python handler, and reworked handler and conductor event/job discovery to be more modular
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
|
||||
"""
|
||||
This file contains definitions for a MEOW recipe based off of jupyter notebooks,
|
||||
along with an appropriate handler for said events.
|
||||
This file contains definitions for a MEOW recipe based off of jupyter
|
||||
notebooks, along with an appropriate handler for said events.
|
||||
|
||||
Author(s): David Marchant
|
||||
"""
|
||||
@ -13,12 +13,13 @@ import sys
|
||||
from typing import Any
|
||||
|
||||
from core.correctness.validation import check_type, valid_string, \
|
||||
valid_dict, valid_path, valid_existing_dir_path, setup_debugging
|
||||
valid_dict, valid_path, valid_existing_dir_path, setup_debugging, \
|
||||
valid_event
|
||||
from core.correctness.vars import VALID_VARIABLE_NAME_CHARS, PYTHON_FUNC, \
|
||||
DEBUG_INFO, WATCHDOG_TYPE, JOB_HASH, PYTHON_EXECUTION_BASE, \
|
||||
WATCHDOG_RULE, EVENT_PATH, PYTHON_TYPE, WATCHDOG_HASH, JOB_PARAMETERS, \
|
||||
DEBUG_INFO, EVENT_TYPE_WATCHDOG, JOB_HASH, PYTHON_EXECUTION_BASE, \
|
||||
EVENT_PATH, JOB_TYPE_PYTHON, WATCHDOG_HASH, JOB_PARAMETERS, \
|
||||
PYTHON_OUTPUT_DIR, JOB_ID, WATCHDOG_BASE, META_FILE, BASE_FILE, \
|
||||
PARAMS_FILE, JOB_STATUS, STATUS_QUEUED
|
||||
PARAMS_FILE, JOB_STATUS, STATUS_QUEUED, EVENT_RULE, EVENT_TYPE, EVENT_RULE
|
||||
from core.functionality import print_debug, create_job, replace_keywords, \
|
||||
make_dir, write_yaml, write_notebook
|
||||
from core.meow import BaseRecipe, BaseHandler
|
||||
@ -91,7 +92,7 @@ class PapermillHandler(BaseHandler):
|
||||
print_debug(self._print_target, self.debug_level,
|
||||
f"Handling event {event[EVENT_PATH]}", DEBUG_INFO)
|
||||
|
||||
rule = event[WATCHDOG_RULE]
|
||||
rule = event[EVENT_RULE]
|
||||
|
||||
# Assemble job parameters dict from pattern variables
|
||||
yaml_dict = {}
|
||||
@ -122,10 +123,19 @@ class PapermillHandler(BaseHandler):
|
||||
yaml_dict[value[0]] = value[1]
|
||||
self.setup_job(event, yaml_dict)
|
||||
|
||||
def valid_event_types(self)->list[str]:
|
||||
"""Function to provide a list of the types of events this handler can
|
||||
process."""
|
||||
return [WATCHDOG_TYPE]
|
||||
def valid_handle_criteria(self, event:dict[str,Any])->bool:
|
||||
"""Function to determine given an event defintion, if this handler can
|
||||
process it or not. This handler accepts events from watchdog with
|
||||
jupyter notebook recipes."""
|
||||
try:
|
||||
valid_event(event)
|
||||
if type(event[EVENT_RULE].recipe) == JupyterNotebookRecipe \
|
||||
and event[EVENT_TYPE] == EVENT_TYPE_WATCHDOG:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def _is_valid_handler_base(self, handler_base)->None:
|
||||
"""Validation check for 'handler_base' variable from main
|
||||
@ -141,7 +151,7 @@ class PapermillHandler(BaseHandler):
|
||||
"""Function to set up new job dict and send it to the runner to be
|
||||
executed."""
|
||||
meow_job = create_job(
|
||||
PYTHON_TYPE,
|
||||
JOB_TYPE_PYTHON,
|
||||
event,
|
||||
{
|
||||
JOB_PARAMETERS:yaml_dict,
|
||||
@ -153,7 +163,7 @@ class PapermillHandler(BaseHandler):
|
||||
)
|
||||
print_debug(self._print_target, self.debug_level,
|
||||
f"Creating job from event at {event[EVENT_PATH]} of type "
|
||||
f"{PYTHON_TYPE}.", DEBUG_INFO)
|
||||
f"{JOB_TYPE_PYTHON}.", DEBUG_INFO)
|
||||
|
||||
# replace MEOW keyworks within variables dict
|
||||
yaml_dict = replace_keywords(
|
||||
@ -174,7 +184,7 @@ class PapermillHandler(BaseHandler):
|
||||
|
||||
# write an executable notebook to the job directory
|
||||
base_file = os.path.join(job_dir, BASE_FILE)
|
||||
write_notebook(event[WATCHDOG_RULE].recipe.recipe, base_file)
|
||||
write_notebook(event[EVENT_RULE].recipe.recipe, base_file)
|
||||
|
||||
# write a parameter file to the job directory
|
||||
param_file = os.path.join(job_dir, PARAMS_FILE)
|
||||
@ -196,7 +206,7 @@ def job_func(job):
|
||||
from datetime import datetime
|
||||
from core.functionality import write_yaml, read_yaml, write_notebook, \
|
||||
get_file_hash, parameterize_jupyter_notebook
|
||||
from core.correctness.vars import JOB_EVENT, WATCHDOG_RULE, JOB_ID, \
|
||||
from core.correctness.vars import JOB_EVENT, EVENT_RULE, JOB_ID, \
|
||||
EVENT_PATH, META_FILE, PARAMS_FILE, JOB_FILE, RESULT_FILE, \
|
||||
JOB_STATUS, JOB_HASH, SHA256, STATUS_SKIPPED, JOB_END_TIME, \
|
||||
JOB_ERROR, STATUS_FAILED, PYTHON_EXECUTION_BASE
|
||||
@ -235,7 +245,7 @@ def job_func(job):
|
||||
# Create a parameterised version of the executable notebook
|
||||
try:
|
||||
job_notebook = parameterize_jupyter_notebook(
|
||||
event[WATCHDOG_RULE].recipe.recipe, yaml_dict
|
||||
event[EVENT_RULE].recipe.recipe, yaml_dict
|
||||
)
|
||||
write_notebook(job_notebook, job_file)
|
||||
except Exception as e:
|
||||
|
Reference in New Issue
Block a user