Toloka documentation

PoolStatusObserver

toloka.streaming.observer.PoolStatusObserver | Source code

PoolStatusObserver(
    self,
    toloka_client: Union[TolokaClient, AsyncTolokaClient],
    pool_id: str,
    *,
    name: Optional[str] = None
)

Observer for pool status change.

For usage with Pipeline.

Allow to register callbacks using the following methods: * on_open * on_closed * on_archieved * on_locked * on_status_change

The Pool object will be passed to the triggered callbacks.

Parameters Description

Parameters Type Description
toloka_client AsyncInterfaceWrapper[Union[TolokaClient, AsyncTolokaClient]]

TolokaClient instance or async wrapper around it.

pool_id str

Pool ID.

Examples:

Bind to the pool's close to make some aggregations.

def call_this_on_close(pool: Pool) -> None:
    assignments = client.get_assignments_df(pool_id=pool.id, status=['APPROVED'])
    do_some_aggregation(assignments)
observer = PoolStatusObserver(toloka_client, pool_id='123')
observer.on_close(call_this_on_close)

Call something at any status change.

observer.on_status_change(lambda pool: ...)

Methods Summary

Method Description
inject None
on_archieved None
on_closed None
on_locked None
on_open None
on_status_change None
register_callback Register given callable for pool status change to given value.