Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
orchestra-v3
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Alessandro Di Federico
orchestra-v3
Commits
81db1f88
Commit
81db1f88
authored
4 years ago
by
Filippo Cremonese
Browse files
Options
Downloads
Patches
Plain Diff
Refactored executor: stop scheduling new jobs if one fails
parent
ae8268e2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
orchestra/executor.py
+26
-16
26 additions, 16 deletions
orchestra/executor.py
with
26 additions
and
16 deletions
orchestra/executor.py
+
26
−
16
View file @
81db1f88
import
logging
from
concurrent
import
futures
from
typing
import
List
from
.model.actions.action
import
Action
class
Executor
:
def
__init__
(
self
,
threads
=
1
,
show_output
=
False
):
self
.
pending_actions
=
set
()
self
.
futures
=
[]
self
.
threads
=
1
self
.
show_output
=
show_output
self
.
pool
=
futures
.
ThreadPoolExecutor
(
max_workers
=
threads
,
thread_name_prefix
=
"
Builder
"
)
self
.
_pending_actions
=
set
()
self
.
_running_actions
:
List
[
futures
.
Future
]
=
[]
self
.
_pool
=
futures
.
ThreadPoolExecutor
(
max_workers
=
threads
,
thread_name_prefix
=
"
Builder
"
)
def
run
(
self
,
action
,
force
=
False
):
self
.
_collect_actions
(
action
,
force
=
force
)
...
...
@@ -18,23 +19,32 @@ class Executor:
for
_
in
range
(
self
.
threads
):
self
.
_schedule_next
()
while
self
.
future
s
:
done
,
not_done
=
futures
.
wait
(
self
.
future
s
,
return_when
=
futures
.
FIRST_COMPLETED
)
while
self
.
_running_action
s
:
done
,
not_done
=
futures
.
wait
(
self
.
_running_action
s
,
return_when
=
futures
.
FIRST_COMPLETED
)
for
d
in
done
:
self
.
futures
.
remove
(
d
)
self
.
_schedule_next
()
self
.
_running_actions
.
remove
(
d
)
exception
=
d
.
exception
()
if
exception
:
logging
.
critical
(
"
An action failed!
"
)
logging
.
critical
(
exception
)
if
self
.
_pending_actions
:
logging
.
critical
(
"
Waiting for other running actions to terminate
"
)
self
.
_pending_actions
=
set
()
else
:
self
.
_schedule_next
()
if
self
.
pending_actions
:
# Todo: remove these 4 lines
if
self
.
_pending_actions
:
logging
.
error
(
"
Could not schedule any action, something failed
"
)
logging
.
error
(
f
"
Remaining:
{
self
.
pending_actions
}
"
)
logging
.
error
(
f
"
Remaining:
{
self
.
_
pending_actions
}
"
)
breakpoint
()
def
_collect_actions
(
self
,
action
:
Action
,
force
=
False
):
if
not
force
and
action
.
is_satisfied
():
return
if
action
not
in
self
.
pending_actions
:
self
.
pending_actions
.
add
(
action
)
if
action
not
in
self
.
_
pending_actions
:
self
.
_
pending_actions
.
add
(
action
)
for
dep
in
action
.
dependencies
:
self
.
_collect_actions
(
dep
)
...
...
@@ -44,14 +54,14 @@ class Executor:
logging
.
debug
(
f
"
Did not find more runnable actions
"
)
return
future
=
self
.
pool
.
submit
(
self
.
_run_action
,
next_runnable_action
)
self
.
future
s
.
append
(
future
)
future
=
self
.
_
pool
.
submit
(
self
.
_run_action
,
next_runnable_action
)
self
.
_running_action
s
.
append
(
future
)
def
_get_next_runnable_action
(
self
):
for
action
in
self
.
pending_actions
:
for
action
in
self
.
_
pending_actions
:
if
all
([
d
.
is_satisfied
()
for
d
in
action
.
dependencies
]):
self
.
pending_actions
.
remove
(
action
)
self
.
_
pending_actions
.
remove
(
action
)
return
action
def
_run_action
(
self
,
action
:
Action
):
action
.
run
(
show_output
=
self
.
show_output
)
return
action
.
run
(
show_output
=
self
.
show_output
)
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