Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
b54eaced
Commit
b54eaced
authored
9 years ago
by
Nathaniel Kofalt
Browse files
Options
Downloads
Patches
Plain Diff
Port #69 to master
parent
6c8b0fc6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/jobs.py
+24
-14
24 additions, 14 deletions
api/jobs.py
with
24 additions
and
14 deletions
api/jobs.py
+
24
−
14
View file @
b54eaced
...
...
@@ -31,23 +31,22 @@ JOB_STATES_ALLOWED_MUTATE = [
]
JOB_TRANSITIONS
=
[
"
pending --> running
"
,
"
running --> failed
"
,
"
running --> complete
"
,
'
pending --> running
'
,
'
running --> failed
'
,
'
running --> complete
'
,
]
def
valid_transition
(
from_state
,
to_state
):
return
(
from_state
+
"
-->
"
+
to_state
)
in
JOB_TRANSITIONS
or
from_state
==
to_state
return
(
from_state
+
'
-->
'
+
to_state
)
in
JOB_TRANSITIONS
or
from_state
==
to_state
ALGORITHMS
=
[
"
dcm2nii
"
'
dcm2nii
'
]
# A FileInput tuple holds all the details of a scitran file that needed to use that as an input a formula.
FileInput
=
namedtuple
(
'
input
'
,
[
'
container_type
'
,
'
container_id
'
,
'
filename
'
,
'
filehash
'
])
# Convert a dictionary to a FileInput
# REVIEW: less irritating conversion?
def
convert_to_fileinput
(
d
):
return
FileInput
(
container_type
=
d
[
'
container_type
'
],
...
...
@@ -141,25 +140,26 @@ def retry_job(db, j, force=False):
log
.
info
(
'
permanently failed job %s (after %d attempts)
'
%
(
j
[
'
_id
'
],
j
[
'
attempt
'
]))
def
generate_formula
(
i
):
def
generate_formula
(
algorithm_id
,
i
):
"""
Given an intent, generates a formula to execute a job.
Parameters
----------
i: map
A job
'
s intent that holds everything needed to generate a formula.
algorithm_id: string
Human-friendly unique name of the algorithm
i: FileInput
The input to be used by this job
"""
if
i
[
'
algorithm_id
'
]
not
in
ALGORITHMS
:
if
algorithm_id
not
in
ALGORITHMS
:
raise
Exception
(
'
Usupported algorithm
'
+
algorithm_id
)
# Currently hard-coded for a single algorithm: dcm2nii
f
=
{
'
inputs
'
:
[
{
'
type
'
:
'
file
'
,
'
uri
'
:
'
/op
t/flywheel-temp/dcm_convert-0.1.1.tar
'
,
'
uri
'
:
'
/
n
op
e.txt
'
,
'
location
'
:
'
/
'
,
},
{
...
...
@@ -169,7 +169,7 @@ def generate_formula(i):
}
],
'
transform
'
:
{
'
command
'
:
[
'
bash
'
,
'
-c
'
,
'
mkdir /output; /scripts/run /input/
'
+
i
[
'
filename
'
]
+
'
/output/
'
+
i
[
'
filename
'
].
split
(
'
_
'
)[
0
]
],
'
command
'
:
[
'
echo
'
,
'
No command specified for
'
+
algorithm_id
],
'
env
'
:
{
},
'
dir
'
:
"
/
"
,
},
...
...
@@ -183,6 +183,16 @@ def generate_formula(i):
],
}
if
algorithm_id
==
'
dcm2nii
'
:
f
[
'
inputs
'
][
0
][
'
uri
'
]
=
'
/opt/flywheel-temp/dcm_convert-0.1.1.tar
'
f
[
'
transform
'
][
'
command
'
]
=
[
'
bash
'
,
'
-c
'
,
'
mkdir /output; /scripts/run /input/
'
+
i
[
'
filename
'
]
+
'
/output/
'
+
i
[
'
filename
'
].
split
(
'
_
'
)[
0
]]
elif
algorithm_id
==
'
qa
'
:
f
[
'
inputs
'
][
0
][
'
uri
'
]
=
'
/opt/flywheel-temp/qa-report-fmri-0.0.2.tar
'
f
[
'
transform
'
][
'
command
'
]
=
[
'
bash
'
,
'
-c
'
,
'
mkdir /output; /scripts/run; exit 0
'
]
else
:
raise
Exception
(
'
Command for algorithm
'
+
algorithm_id
+
'
not specified
'
)
return
f
class
Jobs
(
base
.
RequestHandler
):
...
...
@@ -238,7 +248,7 @@ class Jobs(base.RequestHandler):
'
_id
'
:
result
[
'
_id
'
]
},
{
'
$set
'
:
{
'
request
'
:
generate_formula
(
result
[
'
inten
t
'
])}
'
request
'
:
generate_formula
(
result
[
'
algorithm_id
'
],
result
[
'
inpu
t
'
])}
},
return_document
=
pymongo
.
collection
.
ReturnDocument
.
AFTER
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment