harp_apps.janitor.worker

Inheritance diagram of harp_apps.janitor.worker

class JanitorWorker[source]

Bases: object

__init__(storage, blob_storage)[source]
Parameters:
async compute_and_store_metrics(*, session)[source]

Compute counts of objects in storage, and store them as metrics.

async compute_metrics(session)[source]
async delete_old_transactions(*, session)[source]

Remove transactions older than OLD_AFTER days. On correct database implementations (postgresql for example), it will cascade to related objects. On sqlite, there will be garbage left, but it’s not a big deal.

async delete_orphan_blobs(*, session)[source]

Find and remove blobs that are not referenced anymore by any transaction.

async do_count(session, name, /, *, method='count')[source]

Helper to count objects in storage, from different repositories and using different methods for building the actual query.

Parameters:
  • session – sqlalchemy async session

  • name (str) – repository name (should be available from storage)

  • method – method name to call on the repository to get the actual sqlalchemy query, default as “count”

Returns:

integer

async loop()[source]

One iteration of the janitor loop.

async run()[source]

Once dependencies are ready, start the main loop (basically, run the loop() every PERIOD seconds), until stop() is called.

stop()[source]

Mark the loop for termination.