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 4 commits
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
2 changes: 1 addition & 1 deletion api/jobs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def get_config(self, _id):
# Detect if config is old- or new-style.
# TODO: remove this logic with a DB upgrade, ref database.py's reserved upgrade section.

if c.get('config') is not None and c.get('inputs') is not None:
if 'config' in c and c.get('inputs') is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the rationale behind this change? This would fail if c['config'] is None.

Copy link
Contributor Author

@nagem nagem Oct 24, 2017

Choose a reason for hiding this comment

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

It was failing when the config key existed but was not set. AKA, it was the "new" style, but there was no config for the job. There were inputs and destination.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out-of-band: Given that this is a database anti-upgrade hackaround, let's just run with this for now 👍

# New behavior

# API keys are only returned in-flight, when the job is running, and not persisted to the job object.
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
11 changes: 9 additions & 2 deletions api/jobs/rules.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import fnmatch

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

from . import gears
from .jobs import Job
from .queue import Queue

log = config.log

Expand Down Expand Up @@ -235,11 +237,16 @@ def create_jobs(db, container_before, container_after, container_type):


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

for pj in potential_jobs:
pj['job'].insert()
spawned_jobs.append(pj['rule']['alg'])
job_map = pj['job'].map()
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'])

return spawned_jobs

Expand Down