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
buildgrid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container registry
Model registry
Operate
Environments
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 GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
BuildGrid
buildgrid
Commits
4566b71b
Commit
4566b71b
authored
6 years ago
by
Finn
Browse files
Options
Downloads
Patches
Plain Diff
Implement cancelletion methods in job class.
parent
cc5b0c91
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
buildgrid/server/job.py
+34
-1
34 additions, 1 deletion
buildgrid/server/job.py
with
34 additions
and
1 deletion
buildgrid/server/job.py
+
34
−
1
View file @
4566b71b
...
...
@@ -19,6 +19,7 @@ import uuid
from
google.protobuf
import
timestamp_pb2
from
buildgrid._enums
import
LeaseState
,
OperationStage
from
buildgrid._exceptions
import
CancelledError
from
buildgrid._protos.build.bazel.remote.execution.v2
import
remote_execution_pb2
from
buildgrid._protos.google.devtools.remoteworkers.v1test2
import
bots_pb2
from
buildgrid._protos.google.longrunning
import
operations_pb2
...
...
@@ -37,10 +38,14 @@ class Job:
self
.
__execute_response
=
None
self
.
__operation_metadata
=
remote_execution_pb2
.
ExecuteOperationMetadata
()
self
.
__queued_timestamp
=
timestamp_pb2
.
Timestamp
()
self
.
__worker_start_timestamp
=
timestamp_pb2
.
Timestamp
()
self
.
__worker_completed_timestamp
=
timestamp_pb2
.
Timestamp
()
self
.
__operation_cancelled
=
False
self
.
__lease_cancelled
=
False
self
.
__operation_metadata
.
action_digest
.
CopyFrom
(
action_digest
)
self
.
__operation_metadata
.
stage
=
OperationStage
.
UNKNOWN
.
value
...
...
@@ -131,7 +136,9 @@ class Job:
Only one :class:`Lease` can be emitted for a given job. This method
should only be used once, any furhter calls are ignored.
"""
if
self
.
_lease
is
not
None
:
if
self
.
__operation_cancelled
:
return
None
elif
self
.
_lease
is
not
None
:
return
None
self
.
_lease
=
bots_pb2
.
Lease
()
...
...
@@ -189,6 +196,15 @@ class Job:
self
.
__execute_response
.
cached_result
=
False
self
.
__execute_response
.
status
.
CopyFrom
(
status
)
def
cancel_lease
(
self
):
"""
Triggers a job
'
s :class:Lease cancellation.
This will not cancel the job
'
s :class:Operation.
"""
self
.
__lease_cancelled
=
True
if
self
.
_lease
is
not
None
:
self
.
update_lease_state
(
LeaseState
.
CANCELLED
)
def
update_operation_stage
(
self
,
stage
):
"""
Operates a stage transition for the job
'
s :class:Operation.
...
...
@@ -214,3 +230,20 @@ class Job:
for
queue
in
self
.
_operation_update_queues
:
queue
.
put
(
self
.
_operation
)
def
cancel_operation
(
self
):
"""
Triggers a job
'
s :class:Operation cancellation.
This will also cancel any job
'
s :class:Lease that may have been issued.
"""
self
.
__operation_cancelled
=
True
if
self
.
_lease
is
not
None
:
self
.
cancel_lease
()
self
.
__execute_response
=
remote_execution_pb2
.
ExecuteResponse
()
self
.
__execute_response
.
status
.
code
=
code_pb2
.
CANCELLED
self
.
__execute_response
.
status
.
message
=
"
Operation cancelled by client.
"
self
.
update_operation_stage
(
OperationStage
.
COMPLETED
)
raise
CancelledError
(
"
Operation cancelled: {}
"
.
format
(
self
.
_name
))
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