buildgrid.bot.tenantmanager module

class buildgrid.bot.tenantmanager.TenantManager

Bases: object

Manages a number of :class:`Tenant`s.

Creates work to do, monitors and removes leases of work.

create_tenancy(lease: Lease) None

Create a new Tenant.

Parameters:

( (lease) – class:Lease) : Lease of work to do.

remove_tenant(lease_id: str) None

Attempts to remove a tenant.

If the tenant has not been cancelled, it will cancel it. If the tenant has not completed, it will not remove it.

Parameters:

lease_id (string) – The lease id.

get_leases() List[Lease] | None

Returns a list of leases managed by this instance.

get_lease_ids() Iterable[str]

Returns a list of lease ids.

get_lease_state(lease_id: str) LeaseState

Returns the lease state

Parameters:

lease_id (string) – The lease id.

complete_lease(lease_id: str, status: Status, task: Task[bots_pb2.Lease] | None = None) None

Informs the TenantManager that the lease has completed.

If it was not cancelled, it will update with the result returned from the task.

Parameters:
  • lease_id (string) – The lease id.

  • status (Status) – The final status of the lease.

  • task (asyncio.Task) – The task of work.

create_work(lease_id: str, work: WorkItem, context: Any | None) None

Creates work to do.

Will place work on an asyncio loop with a callback to complete_lease.

Parameters:
  • lease_id (string) – The lease id.

  • work (func) – Work to do.

  • context (context) – Context for work function.

cancel_tenancy(lease_id: str) None

Cancels tenancy and any work being done.

Parameters:

lease_id (string) – The lease id.

tenant_completed(lease_id: str) bool

Returns True if the work has been completed.

Parameters:

lease_id (string) – The lease id.

async wait_on_tenants(timeout: float | None) None