buildgrid.bot.tenantmanager module

class buildgrid.bot.tenantmanager.TenantManager

Bases: object

Manages a number of Tenants.

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

create_tenancy(lease)

Create a new Tenant.

Parameters

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

remove_tenant(lease_id)

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()

Returns a list of leases managed by this instance.

get_lease_ids()

Returns a list of lease ids.

get_lease_state(lease_id)

Returns the lease state

Parameters

lease_id (string) – The lease id.

complete_lease(lease_id, status, task=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, work, context)

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)

Cancels tenancy and any work being done.

Parameters

lease_id (string) – The lease id.

tenant_completed(lease_id)

Returns True if the work has been completed.

Parameters

lease_id (string) – The lease id.

async wait_on_tenants(timeout)