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
a6c06f1a
Commit
a6c06f1a
authored
6 years ago
by
Martin Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
job.py: Implement operation cancellation
parent
2c006309
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
buildgrid/server/job.py
+20
-0
20 additions, 0 deletions
buildgrid/server/job.py
with
20 additions
and
0 deletions
buildgrid/server/job.py
+
20
−
0
View file @
a6c06f1a
...
...
@@ -20,6 +20,7 @@ from enum import Enum
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
from
buildgrid._protos.google.rpc
import
code_pb2
class
OperationStage
(
Enum
):
...
...
@@ -60,6 +61,7 @@ class Job:
self
.
__execute_response
=
None
self
.
__operation_metadata
=
remote_execution_pb2
.
ExecuteOperationMetadata
()
self
.
__operation_canceled
=
False
self
.
__operation_metadata
.
action_digest
.
CopyFrom
(
action_digest
)
self
.
__operation_metadata
.
stage
=
OperationStage
.
UNKNOWN
.
value
...
...
@@ -196,6 +198,10 @@ class Job:
self
.
__execute_response
.
cached_result
=
False
self
.
__execute_response
.
status
.
CopyFrom
(
status
)
def
cancel_lease
(
self
):
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.
...
...
@@ -219,3 +225,17 @@ class Job:
for
queue
in
self
.
_operation_update_queues
:
queue
.
put
(
self
.
_operation
)
def
cancel_operation
(
self
):
self
.
__operation_canceled
=
True
self
.
cancel_lease
()
response
=
remote_execution_pb2
.
ExecuteResponse
()
response
.
status
.
code
=
code_pb2
.
CANCELLED
response
.
status
.
message
=
"
The operation was cancelled by the caller.
"
self
.
_operation
.
response
.
Pack
(
response
)
self
.
_operation
.
done
=
True
self
.
update_operation_stage
(
OperationStage
.
COMPLETED
)
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