seperated out rule and job id generation
This commit is contained in:
@ -12,7 +12,7 @@ from core.correctness.vars import EVENT_PATH, EVENT_RULE, EVENT_TYPE, \
|
||||
EVENT_TYPE_WATCHDOG, JOB_CREATE_TIME, JOB_EVENT, JOB_ID, JOB_PATTERN, \
|
||||
JOB_RECIPE, JOB_REQUIREMENTS, JOB_RULE, JOB_STATUS, JOB_TYPE, \
|
||||
STATUS_QUEUED, WATCHDOG_BASE, WATCHDOG_HASH
|
||||
from functionality.naming import generate_id
|
||||
from functionality.naming import generate_job_id
|
||||
|
||||
|
||||
# mig trigger keyword replacements
|
||||
@ -88,7 +88,7 @@ def create_job(job_type:str, event:Dict[str,Any], extras:Dict[Any,Any]={}
|
||||
"""Function to create a MEOW job dictionary."""
|
||||
job_dict = {
|
||||
#TODO compress event?
|
||||
JOB_ID: generate_id(prefix="job_"),
|
||||
JOB_ID: generate_job_id(),
|
||||
JOB_EVENT: event,
|
||||
JOB_TYPE: job_type,
|
||||
JOB_PATTERN: event[EVENT_RULE].pattern.name,
|
||||
|
@ -11,7 +11,7 @@ from core.correctness.vars import CHAR_LOWERCASE, CHAR_UPPERCASE
|
||||
|
||||
|
||||
#TODO Make this guaranteed unique
|
||||
def generate_id(prefix:str="", length:int=16, existing_ids:List[str]=[],
|
||||
def _generate_id(prefix:str="", length:int=16, existing_ids:List[str]=[],
|
||||
charset:str=CHAR_UPPERCASE+CHAR_LOWERCASE, attempts:int=24):
|
||||
random_length = max(length - len(prefix), 0)
|
||||
for _ in range(attempts):
|
||||
@ -21,3 +21,9 @@ def generate_id(prefix:str="", length:int=16, existing_ids:List[str]=[],
|
||||
return id
|
||||
raise ValueError(f"Could not generate ID unique from '{existing_ids}' "
|
||||
f"using values '{charset}' and length of '{length}'.")
|
||||
|
||||
def generate_rule_id():
|
||||
_generate_id(prefix="rule_")
|
||||
|
||||
def generate_job_id():
|
||||
_generate_id(prefix="job_")
|
||||
|
Reference in New Issue
Block a user