Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flamenco-worker-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
flamenco-worker-python
Commits
0b2a2111
Commit
0b2a2111
authored
8 years ago
by
Sybren A. Stüvel
Browse files
Options
Downloads
Patches
Plain Diff
Server: added TaskManager.api_find_job_enders() function for Francesco
parent
7da93f4a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/flamenco/flamenco/tasks/__init__.py
+30
-0
30 additions, 0 deletions
packages/flamenco/flamenco/tasks/__init__.py
packages/flamenco/tests/test_task_manager.py
+51
-1
51 additions, 1 deletion
packages/flamenco/tests/test_task_manager.py
with
81 additions
and
1 deletion
packages/flamenco/flamenco/tasks/__init__.py
+
30
−
0
View file @
0b2a2111
...
@@ -107,6 +107,36 @@ class TaskManager(object):
...
@@ -107,6 +107,36 @@ class TaskManager(object):
task
.
patch
({
'
op
'
:
'
set-task-status
'
,
task
.
patch
({
'
op
'
:
'
set-task-status
'
,
'
status
'
:
new_status
},
api
=
api
)
'
status
'
:
new_status
},
api
=
api
)
def
api_find_job_enders
(
self
,
job_id
):
"""
Returns a list of tasks that could be the last tasks of a job.
In other words, returns all tasks that are not a parent of other tasks.
:returns: list of task IDs
:rtype: list
"""
from
flamenco
import
current_flamenco
tasks_coll
=
current_flamenco
.
db
(
'
tasks
'
)
# Get the distinct set of tasks used as parents.
parent_tasks
=
tasks_coll
.
aggregate
([
{
'
$match
'
:
{
'
job
'
:
job_id
}},
{
'
$project
'
:
{
'
parents
'
:
1
}},
{
'
$unwind
'
:
{
'
path
'
:
'
$parents
'
}},
{
'
$group
'
:
{
'
_id
'
:
'
$parents
'
}},
])
parent_ids
=
[
t
[
'
_id
'
]
for
t
in
parent_tasks
]
# Get all the tasks that do not have such an ID.
tasks
=
tasks_coll
.
find
({
'
job
'
:
job_id
,
'
_id
'
:
{
'
$nin
'
:
parent_ids
}},
projection
=
{
'
_id
'
:
1
})
tids
=
[
t
[
'
_id
'
]
for
t
in
tasks
]
return
tids
def
setup_app
(
app
):
def
setup_app
(
app
):
from
.
import
eve_hooks
,
patch
from
.
import
eve_hooks
,
patch
...
...
This diff is collapsed.
Click to expand it.
packages/flamenco/tests/test_task_manager.py
+
51
−
1
View file @
0b2a2111
...
@@ -34,7 +34,7 @@ class TaskManagerTest(AbstractFlamencoTest):
...
@@ -34,7 +34,7 @@ class TaskManagerTest(AbstractFlamencoTest):
commands
.
Sleep
(
time_in_seconds
=
3
),
commands
.
Sleep
(
time_in_seconds
=
3
),
],
],
'
sleep-1-13
'
,
'
sleep-1-13
'
,
)
,
)
# Now test the database contents.
# Now test the database contents.
with
self
.
app
.
test_request_context
():
with
self
.
app
.
test_request_context
():
...
@@ -57,3 +57,53 @@ class TaskManagerTest(AbstractFlamencoTest):
...
@@ -57,3 +57,53 @@ class TaskManagerTest(AbstractFlamencoTest):
u
'
time_in_seconds
'
:
3
,
u
'
time_in_seconds
'
:
3
,
}
}
},
dbtask
[
'
commands
'
][
1
])
},
dbtask
[
'
commands
'
][
1
])
def
test_api_find_jobfinal_tasks
(
self
):
from
pillar.api.utils.authentication
import
force_cli_user
from
flamenco.job_compilers
import
commands
manager
,
_
,
_
=
self
.
create_manager_service_account
()
with
self
.
app
.
test_request_context
():
force_cli_user
()
job_doc
=
self
.
jmngr
.
api_create_job
(
'
test job
'
,
u
'
Wörk wørk w°rk.
'
,
'
sleep
'
,
{
'
frames
'
:
'
12-18, 20-22
'
,
'
chunk_size
'
:
7
,
'
time_in_seconds
'
:
3
,
},
self
.
proj_id
,
ctd
.
EXAMPLE_PROJECT_OWNER_ID
,
manager
[
'
_id
'
],
)
job_id
=
job_doc
[
'
_id
'
]
# Find the tasks created so far, use them as parents.
tasks
=
self
.
flamenco
.
db
(
'
tasks
'
).
find
({
'
job
'
:
job_id
},
projection
=
{
'
_id
'
:
1
})
task_ids
=
[
t
[
'
_id
'
]
for
t
in
tasks
]
# dependent task that is used as a single parent.
taskid1
=
self
.
tmngr
.
api_create_task
(
job_doc
,
[
commands
.
Echo
(
message
=
u
'
ẑžƶźz
'
)],
'
zzz 1
'
,
parents
=
task_ids
,
)
# task dependent on multiple tasks that is not used as a parent.
taskid2
=
self
.
tmngr
.
api_create_task
(
job_doc
,
[
commands
.
Echo
(
message
=
u
'
ẑžƶźz
'
)],
'
zzz 2
'
,
parents
=
task_ids
,
)
# task dependent on a single task that is not used as a parent.
taskid3
=
self
.
tmngr
.
api_create_task
(
job_doc
,
[
commands
.
Echo
(
message
=
u
'
ẑžƶźz
'
)],
'
zzz 3
'
,
parents
=
[
taskid1
],
)
# independent task
taskid4
=
self
.
tmngr
.
api_create_task
(
job_doc
,
[
commands
.
Echo
(
message
=
u
'
ẑžƶźz
'
)],
'
zzz 4
'
,
)
job_enders
=
self
.
tmngr
.
api_find_job_enders
(
job_id
)
self
.
assertEqual
({
taskid2
,
taskid3
,
taskid4
},
set
(
job_enders
))
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