buildgrid.server.scheduler module

Scheduler

Schedules jobs.

class buildgrid.server.scheduler.Scheduler(data_store, action_cache=None, action_browser_url=False, monitor=False, max_execution_timeout=None)

Bases: object

MAX_N_TRIES = 5
property instance_name
set_instance_name(instance_name)
list_current_jobs()

Returns a list of the Job names currently managed.

register_job_peer(job_name, peer)

Subscribes to the job’s Operation stage changes.

Parameters
  • job_name (str) – name of the job to subscribe to.

  • peer (str) – a unique string identifying the client.

Returns

The name of the subscribed Operation.

Return type

str

Raises

NotFoundError – If no job with job_name exists.

register_job_operation_peer(operation_name, peer)

Subscribes to an existing the job’s Operation stage changes.

Parameters
  • operation_name (str) – name of the operation to subscribe to.

  • peer (str) – a unique string identifying the client.

Returns

The name of the subscribed Operation.

Return type

str

Raises

NotFoundError – If no operation with operation_name exists.

stream_operation_updates(operation_name, context)
unregister_job_operation_peer(operation_name, peer, discard_unwatched_jobs: bool = False)

Unsubscribes to one of the job’s Operation stage change.

Parameters
  • operation_name (str) – name of the operation to unsubscribe from.

  • peer (str) – a unique string identifying the client.

  • discard_unwatched_jobs (bool) – don’t remove operation when client rpc is terminated.

Raises

NotFoundError – If no operation with operation_name exists.

queue_job_action(action, action_digest, platform_requirements={}, priority=0, skip_cache_lookup=False)

Inserts a newly created job into the execution queue.

Warning

Priority is handle like a POSIX nice values: a higher value means a low priority, 0 being default priority.

Parameters
  • action (Action) – the given action to queue for execution.

  • action_digest (Digest) – the digest of the given action.

  • platform_requirements (dict(set)) – platform attributes that a worker must satisfy in order to be assigned the job. (Each key can have multiple values.)

  • priority (int) – the execution job’s priority.

  • skip_cache_lookup (bool) – whether or not to look for pre-computed result for the given action.

Returns

the newly created job’s name.

Return type

str

get_job_operation(operation_name)

Retrieves a job’s Operation by name.

Parameters

operation_name (str) – name of the operation to query.

Raises

NotFoundError – If no operation with operation_name exists.

cancel_job_operation(operation_name)

“Cancels a job’s Operation by name.

Parameters

operation_name (str) – name of the operation to cancel.

Raises

NotFoundError – If no operation with operation_name exists.

delete_job_operation(operation_name)

“Removes a job.

Parameters

operation_name (str) – name of the operation to delete.

Raises

NotFoundError – If no operation with operation_name exists.

get_all_operations() → List[google.longrunning.operations_pb2.Operation]
request_job_leases(worker_capabilities, timeout=None, worker_name=None, bot_id=None)

Generates a list of the highest priority leases to be run.

Parameters
  • worker_capabilities (dict) – a set of key-value pairs describing the worker properties, configuration and state at the time of the request.

  • timeout (int) – time to block waiting on job queue, caps if longer than MAX_JOB_BLOCK_TIME

  • worker_name (string) – name of the worker requesting the leases.

update_job_lease_state(job_name, lease)

Requests a state transition for a job’s current :class:Lease.

Note

This may trigger a job’s Operation stage transition.

Parameters
  • job_name (str) – name of the job to update lease state from.

  • lease (Lease) – the lease holding the new state.

Raises

NotFoundError – If no job with job_name exists.

retry_job_lease(job_name)

Re-queues a job on lease execution failure.

Note

This may trigger a job’s Operation stage transition.

Parameters

job_name (str) – name of the job to retry the lease from.

Raises

NotFoundError – If no job with job_name exists.

get_job_lease(job_name)

Returns the lease associated to job, if any have been emitted yet.

Parameters

job_name (str) – name of the job to query the lease from.

Raises

NotFoundError – If no job with job_name exists.

delete_job_lease(job_name)

Discards the lease associated with a job.

Parameters

job_name (str) – name of the job to delete the lease from.

Raises

NotFoundError – If no job with job_name exists.

get_job_lease_cancelled(job_name)

Returns true if the lease is cancelled.

Parameters

job_name (str) – name of the job to query the lease state from.

Raises

NotFoundError – If no job with job_name exists.

property is_instrumented
activate_monitoring()

Activated jobs monitoring.

deactivate_monitoring()

Deactivated jobs monitoring.

register_build_metadata_watcher(message_queue)
get_metrics()
query_n_retries()
query_am_queue_time()