Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use central job enqueue logic for jobs spawned by rules #962

Merged
merged 6 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/jobs/gears.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def validate_gear_config(gear, config_):
})
return True

def fill_gear_default_values(gear, config_):
"""
Given a gear and a config map, fill any missing keys using defaults from the gear's config
"""

for k,v in gear['gear'].get('config', {}).itervalues:
if 'default' in v:
config_.setdefault(k, v['default'])


def insert_gear(doc):
gear_tools.validate_manifest(doc['gear'])

Expand Down
3 changes: 2 additions & 1 deletion api/jobs/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .. import config
from .jobs import Job
from .gears import get_gear, validate_gear_config
from .gears import get_gear, validate_gear_config, fill_gear_default_values
from ..validators import InputValidationException
from ..dao.containerutil import create_filereference_from_dictionary, create_containerreference_from_dictionary, create_containerreference_from_filereference

Expand Down Expand Up @@ -157,6 +157,7 @@ def enqueue_job(job_map, origin, perm_check_uid=None):
raise InputValidationException('Gear marked as invalid, will not run!')

config_ = job_map.get('config', {})
fill_gear_default_values(gear, config_)
validate_gear_config(gear, config_)

# Translate maps to FileReferences
Expand Down
7 changes: 6 additions & 1 deletion api/jobs/rules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fnmatch

from .. import config
from ..types import Origin
from ..dao.containerutil import FileReference

from . import gears
Expand Down Expand Up @@ -236,10 +237,14 @@ def create_jobs(db, container_before, container_after, container_type):


spawned_jobs = []
origin ={
'type': str(Origin.system),
'id': None
}

for pj in potential_jobs:
job_map = pj['job'].map()
Queue.enqueue_job(job_map, None) # passing no origin results in system origin
Queue.enqueue_job(job_map, origin) # passing no origin results in system origin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove that comment now


spawned_jobs.append(pj['rule']['alg'])

Expand Down