buildgrid.server.job module

class buildgrid.server.job.Job(do_not_cache, action_digest, platform_requirements=None, priority=0, name=None, operation_names=[], cancelled_operation_names=[], lease=None, stage=0, cancelled=False, queued_timestamp=None, queued_time_duration=None, worker_start_timestamp=None, worker_completed_timestamp=None, result=None, worker_name=None, n_tries=0, status_code=None, stdout_stream_name=None, stdout_stream_write_name=None, stderr_stream_name=None, stderr_stream_write_name=None)

Bases: object

property name
property cancelled
property priority
set_priority(new_priority, *, data_store)
property done
property platform_requirements
property do_not_cache
property action_digest
property operation_stage
property operation_metadata
property action_result
property execute_response
property holds_cached_result
property queued_timestamp
property queued_timestamp_as_datetime
property queued_time_duration
property worker_start_timestamp
property worker_start_timestamp_as_datetime
property worker_completed_timestamp
property worker_completed_timestamp_as_datetime
mark_worker_started()
get_metadata(writeable_streams=False)
set_action_url(url)

Generates a CAS browser URL for the job’s action.

set_cached_result(action_result, data_store)

Allows specifying an action result from the action cache for the job.

Note

This won’t trigger any Operation stage transition.

Parameters

action_result (ActionResult) – The result from cache.

n_peers(watch_spec)
n_peers_for_operation(operation_name, watch_spec)
register_new_operation(*, data_store)

Subscribes to a new job’s Operation stage changes.

Returns

The name of the subscribed Operation.

Return type

str

get_all_operations() → List[google.longrunning.operations_pb2.Operation]

Gets all Operation objects related to a job.

Returns

A list of Operation objects.

Return type

list

get_operation(operation_name: str) → google.longrunning.operations_pb2.Operation
Returns a copy of the the job’s Operation

with all the fields populated from the job fields

Parameters

operation_name (str) – the operation’s name.

Raises

NotFoundError – If no operation with operation_name exists.

update_operation_stage(stage, *, data_store)

Operates a stage transition for the job’s Operation.

Parameters

stage (OperationStage) – the operation stage to transition to.

cancel_all_operations(*, data_store)
cancel_operation(operation_name, *, data_store)

Triggers a job’s Operation cancellation.

This may cancel any job’s Lease that may have been issued.

Parameters

operation_name (str) – the operation’s name.

Raises

NotFoundError – If no operation with operation_name exists.

property lease
property lease_state
property lease_cancelled
property n_tries
property status_code
create_lease(worker_name, bot_id=None, *, data_store)

Emits a new Lease for the job.

Only one Lease can be emitted for a given job. This method should only be used once, any further calls are ignored.

Parameters
  • worker_name (string) – The name of the worker this lease is for.

  • bot_id (string) – The name of the corresponding bot for this job’s worker.

update_lease_state(state, status=None, result=None, action_cache=None, *, data_store, skip_lease_persistence=False, skip_notify=False)

Operates a state transition for the job’s current Lease.

Parameters
  • state (LeaseState) – the lease state to transition to.

  • status (google.rpc.Status, optional) – the lease execution status, only required if state is COMPLETED.

  • result (google.protobuf.Any, optional) – the lease execution result, only required if state is COMPLETED.

  • action_cache (ActionCache) – The ActionCache object, only needed to store results

  • skip_lease_persistence (bool) – Whether to skip storing the lease in the datastore for now

  • skip_notify (bool) – Whether to skip notifying of job changes

cancel_lease(*, data_store)

Triggers a job’s Lease cancellation.

Note

This will not cancel the job’s Operation.

delete_lease()

Discard the job’s Lease.

Note

This will not cancel the job’s Operation.

set_stdout_stream(logstream, *, data_store)
set_stderr_stream(logstream, *, data_store)
query_queue_time()
query_n_retries()
get_operation_update(operation_name)

Get an operation update message tuple.

The returned tuple is of the form

(error, operation)