[Notes] [Git][BuildGrid/buildgrid][mablanch/117-job-scheduler-refactoring] Deleted 2 commits: job.py: Implement operation cancellation



Title: GitLab

Martin Blanchard pushed to branch mablanch/117-job-scheduler-refactoring at BuildGrid / buildgrid

WARNING: The push did not contain any new commits, but force pushed to delete the commits and changes below.

Deleted commits:

2 changed files:

Changes:

  • buildgrid/server/job.py
    ... ... @@ -22,6 +22,7 @@ from enum import Enum
    22 22
     from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
    
    23 23
     from buildgrid._protos.google.devtools.remoteworkers.v1test2 import bots_pb2
    
    24 24
     from buildgrid._protos.google.longrunning import operations_pb2
    
    25
    +from buildgrid._protos.google.rpc import code_pb2
    
    25 26
     
    
    26 27
     
    
    27 28
     class OperationStage(Enum):
    
    ... ... @@ -63,6 +64,7 @@ class Job:
    63 64
             self._n_tries = 0
    
    64 65
     
    
    65 66
             self.__operation_metadata = remote_execution_pb2.ExecuteOperationMetadata()
    
    67
    +        self.__operation_canceled = False
    
    66 68
     
    
    67 69
             self.__operation_metadata.action_digest.CopyFrom(self._action_digest)
    
    68 70
             self.__operation_metadata.stage = OperationStage.UNKNOWN.value
    
    ... ... @@ -139,6 +141,10 @@ class Job:
    139 141
                 self._operation.response.Pack(response)
    
    140 142
                 self._operation.done = True
    
    141 143
     
    
    144
    +    def cancel_lease(self):
    
    145
    +        if self._lease is not None:
    
    146
    +            self.update_lease_state(LeaseState.CANCELLED)
    
    147
    +
    
    142 148
         def update_operation_stage(self, stage):
    
    143 149
             if stage.value == self.__operation_metadata.stage:
    
    144 150
                 return
    
    ... ... @@ -152,3 +158,17 @@ class Job:
    152 158
     
    
    153 159
             for queue in self._operation_update_queues:
    
    154 160
                 queue.put(self._operation)
    
    161
    +
    
    162
    +    def cancel_operation(self):
    
    163
    +        self.__operation_canceled = True
    
    164
    +
    
    165
    +        self.cancel_lease()
    
    166
    +
    
    167
    +        response = remote_execution_pb2.ExecuteResponse()
    
    168
    +        response.status.code = code_pb2.CANCELLED
    
    169
    +        response.status.message = "The operation was cancelled by the caller."
    
    170
    +
    
    171
    +        self._operation.response.Pack(response)
    
    172
    +        self._operation.done = True
    
    173
    +
    
    174
    +        self.update_operation_stage(OperationStage.COMPLETED)

  • buildgrid/server/scheduler.py
    ... ... @@ -83,6 +83,7 @@ class Scheduler:
    83 83
     
    
    84 84
         def update_job_lease_state(self, job_name, lease_state, lease_status=None, lease_result=None):
    
    85 85
             job = self.jobs[job_name]
    
    86
    +
    
    86 87
             if lease_state != LeaseState.COMPLETED:
    
    87 88
                 job.update_lease_state(lease_state)
    
    88 89
             else:
    
    ... ... @@ -100,6 +101,16 @@ class Scheduler:
    100 101
         def get_job_lease(self, name):
    
    101 102
             return self.jobs[name].lease
    
    102 103
     
    
    104
    +    def cancel_job_operation(self, job_name):
    
    105
    +        """"Cancels the underlying operation of a given job.
    
    106
    +
    
    107
    +        This will also cancel any job's lease that may have been issued.
    
    108
    +
    
    109
    +        Args:
    
    110
    +            job_name (str): name of the job holding the operation to cancel.
    
    111
    +        """
    
    112
    +        self.jobs[job_name].cancel_operation()
    
    113
    +
    
    103 114
         def create_lease(self):
    
    104 115
             if self.queue:
    
    105 116
                 job = self.queue.popleft()
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]