Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildstream
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
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
BuildStream
buildstream
Commits
0b50c52e
Commit
0b50c52e
authored
6 years ago
by
Tristan Van Berkom
Browse files
Options
Downloads
Patches
Plain Diff
_scheduler/jobs/job.py: Allow subclasses to message the frontend
parent
60586f80
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
buildstream/_scheduler/jobs/job.py
+50
-19
50 additions, 19 deletions
buildstream/_scheduler/jobs/job.py
with
50 additions
and
19 deletions
buildstream/_scheduler/jobs/job.py
+
50
−
19
View file @
0b50c52e
...
...
@@ -58,10 +58,10 @@ class JobStatus():
# Used to distinguish between status messages and return values
class
Envelope
():
class
_
Envelope
():
def
__init__
(
self
,
message_type
,
message
):
self
.
_
message_type
=
message_type
self
.
_
message
=
message
self
.
message_type
=
message_type
self
.
message
=
message
# Process class that doesn't call waitpid on its own.
...
...
@@ -275,10 +275,37 @@ class Job():
def
set_task_id
(
self
,
task_id
):
self
.
_task_id
=
task_id
# send_message()
#
# To be called from inside Job.child_process() implementations
# to send messages to the main process during processing.
#
# These messages will be processed by the class's Job.handle_message()
# implementation.
#
def
send_message
(
self
,
message_type
,
message
):
self
.
_queue
.
put
(
_Envelope
(
message_type
,
message
))
#######################################################
# Abstract Methods #
#######################################################
# handle_message()
#
# Handle a custom message. This will be called in the main process in
# response to any messages sent to the main proces using the
# Job.send_message() API from inside a Job.child_process() implementation
#
# Args:
# message_type (str): A string to identify the message type
# message (any): A simple serializable object
#
# Returns:
# (bool): Should return a truthy value if message_type is handled.
#
def
handle_message
(
self
,
message_type
,
message
):
return
False
# parent_complete()
#
# This will be executed after the job finishes, and is expected to
...
...
@@ -416,7 +443,7 @@ class Job():
elapsed
=
elapsed
,
detail
=
e
.
detail
,
logfile
=
filename
,
sandbox
=
e
.
sandbox
)
self
.
_queue
.
put
(
Envelope
(
'
child_data
'
,
self
.
child_process_data
()))
self
.
_queue
.
put
(
_
Envelope
(
'
child_data
'
,
self
.
child_process_data
()))
# Report the exception to the parent (for internal testing purposes)
self
.
_child_send_error
(
e
)
...
...
@@ -442,7 +469,7 @@ class Job():
else
:
# No exception occurred in the action
self
.
_queue
.
put
(
Envelope
(
'
child_data
'
,
self
.
child_process_data
()))
self
.
_queue
.
put
(
_
Envelope
(
'
child_data
'
,
self
.
child_process_data
()))
self
.
_child_send_result
(
result
)
elapsed
=
datetime
.
datetime
.
now
()
-
starttime
...
...
@@ -469,7 +496,7 @@ class Job():
domain
=
e
.
domain
reason
=
e
.
reason
envelope
=
Envelope
(
'
error
'
,
{
envelope
=
_
Envelope
(
'
error
'
,
{
'
domain
'
:
domain
,
'
reason
'
:
reason
})
...
...
@@ -487,7 +514,7 @@ class Job():
#
def
_child_send_result
(
self
,
result
):
if
result
is
not
None
:
envelope
=
Envelope
(
'
result
'
,
result
)
envelope
=
_
Envelope
(
'
result
'
,
result
)
self
.
_queue
.
put
(
envelope
)
# _child_shutdown()
...
...
@@ -524,7 +551,7 @@ class Job():
if
message
.
message_type
==
MessageType
.
LOG
:
return
self
.
_queue
.
put
(
Envelope
(
'
message
'
,
message
))
self
.
_queue
.
put
(
_
Envelope
(
'
message
'
,
message
))
# _parent_shutdown()
#
...
...
@@ -588,24 +615,28 @@ class Job():
if
not
self
.
_listening
:
return
if
envelope
.
_
message_type
==
'
message
'
:
if
envelope
.
message_type
==
'
message
'
:
# Propagate received messages from children
# back through the context.
self
.
_scheduler
.
context
.
message
(
envelope
.
_
message
)
elif
envelope
.
_
message_type
==
'
error
'
:
self
.
_scheduler
.
context
.
message
(
envelope
.
message
)
elif
envelope
.
message_type
==
'
error
'
:
# For regression tests only, save the last error domain / reason
# reported from a child task in the main process, this global state
# is currently managed in _exceptions.py
set_last_task_error
(
envelope
.
_
message
[
'
domain
'
],
envelope
.
_
message
[
'
reason
'
])
elif
envelope
.
_
message_type
==
'
result
'
:
set_last_task_error
(
envelope
.
message
[
'
domain
'
],
envelope
.
message
[
'
reason
'
])
elif
envelope
.
message_type
==
'
result
'
:
assert
self
.
_result
is
None
self
.
_result
=
envelope
.
_
message
elif
envelope
.
_
message_type
==
'
child_data
'
:
self
.
_result
=
envelope
.
message
elif
envelope
.
message_type
==
'
child_data
'
:
# If we retry a job, we assign a new value to this
self
.
child_data
=
envelope
.
_message
else
:
raise
Exception
()
self
.
child_data
=
envelope
.
message
# Try Job subclass specific messages now
elif
not
self
.
handle_message
(
envelope
.
message_type
,
envelope
.
message
):
assert
0
,
"
Unhandled message type
'
{}
'
: {}
"
\
.
format
(
envelope
.
message_type
,
envelope
.
message
)
# _parent_process_queue()
#
...
...
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