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
bad266fc
Commit
bad266fc
authored
9 years ago
by
Nathaniel Kofalt
Browse files
Options
Downloads
Patches
Plain Diff
Rules skeleton
parent
36b48614
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/jobs.py
+11
-1
11 additions, 1 deletion
api/jobs.py
api/rules.py
+100
-0
100 additions, 0 deletions
api/rules.py
with
111 additions
and
1 deletion
api/jobs.py
+
11
−
1
View file @
bad266fc
...
...
@@ -41,7 +41,17 @@ ALGORITHMS = [
# TODO: json schema
def
spawn_jobs
(
db
,
containers
,
file
):
def
create_jobs
(
db
,
container
,
container_type
,
file
):
# CHANGES:
# This no longer takes an array, should take string container type and container object
# This calls rules.check_rules
# Some of this lookup logic moves to rules.check_rules
# Rethink what exact data is being stored on a job
# generate_formula gets smarted
#
# OLD DOCS + LOGIC FOLLOW
"""
Spawn some number of queued jobs to process a file.
...
...
This diff is collapsed.
Click to expand it.
api/rules.py
0 → 100644
+
100
−
0
View file @
bad266fc
import
logging
log
=
logging
.
getLogger
(
'
scitran.api.jobs
'
)
import
bson
import
pymongo
import
datetime
from
.
import
base
from
.
import
util
#
# {
# At least one match from this array must succeed, or array must be empty
# "any": [
# ["file.type", "dicom" ] # Match the file's type
# ["file.name", "*.dcm" ] # Match a shell glob for the file name
# ["file.measurements", "diffusion" ] # Match any of the file's measurements
# ["container.measurement", "diffusion" ] # Match the container's primary measurment
# ["container.has-type", "bvec" ] # Match the container having any file (including this one) with this type
# ]
#
# All matches from array must succeed, or array must be empty
# "all": [
# ]
#
# Algorithm to
# "alg": "d2n"
# }
#
MATCH_TYPES
=
[
'
file.type
'
,
'
file.name
'
,
'
file.measurements
'
,
'
container.measurement
'
,
'
container.has-type
'
]
def
eval_match
(
match_type
,
match_param
,
file_
,
container
):
"""
Given a match entry, return if the match succeeded.
"""
if
not
match_type
in
MATCH_TYPES
:
raise
Exception
(
'
Unsupported match type
'
+
match_type
)
if
match_type
==
'
file.type
'
:
pass
elif
match_type
==
'
file.name
'
:
pass
elif
match_type
==
'
file.measurements
'
:
pass
elif
match_type
==
'
container.measurement
'
:
pass
elif
match_type
==
'
container.has-type
'
:
pass
else
raise
Exception
(
'
Unimplemented match type
'
+
match_type
)
def
eval_rule
(
rule
,
file_
,
container
):
"""
Decide if a rule should spawn a job.
"""
# Are there matches in the 'any' set?
must_match
=
len
(
rule
.
get
(
'
any
'
,
[]))
>
0
has_match
=
False
for
match
in
rule
.
get
(
'
any
'
,
[]):
if
eval_match
(
match
[
0
],
match
[
1
],
file_
,
container
):
has_match
=
True
break
# If there were matches in the 'any' array and none of them succeeded
if
must_match
and
not
has_match
:
return
False
# Are there matches in the 'all' set?
for
match
in
rule
.
get
(
'
all
'
,
[]):
if
not
eval_match
(
match
[
0
],
match
[
1
],
file_
,
container
):
return
False
return
True
def
check_rules
(
db
,
file_
,
container
):
"""
Check all rules that apply to this file.
"""
rules
=
[]
# TODO: fetch rules from the project
for
rule
in
rules
:
if
eval_rule
(
rule
,
file_
,
container
):
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