Scheduler¶
Schedulers provide means to schedule callbacks asynchronously.
These are used by the subscriber to call the user-provided callback to process each message.
- class google.cloud.pubsub_v1.subscriber.scheduler.Scheduler[source]¶
Abstract base class for schedulers.
Schedulers are used to schedule callbacks asynchronously.
- abstract property queue¶
A concurrency-safe queue specific to the underlying concurrency implementation.
This queue is used to send messages back to the scheduling actor.
- Type
Queue
- abstract schedule(callback, *args, **kwargs)[source]¶
Schedule the callback to be called asynchronously.
- Parameters
callback (Callable) – The function to call.
args – Positional arguments passed to the function.
kwargs – Key-word arguments passed to the function.
- Returns
None
- abstract shutdown(await_msg_callbacks=False)[source]¶
Shuts down the scheduler and immediately end all pending callbacks.
- Parameters
await_msg_callbacks (bool) – If
True
, the method will block until all currently executing callbacks are done processing. IfFalse
(default), the method will not wait for the currently running callbacks to complete.- Returns
The messages submitted to the scheduler that were not yet dispatched to their callbacks. It is assumed that each message was submitted to the scheduler as the first positional argument to the provided callback.
- Return type
List[pubsub_v1.subscriber.message.Message]
- class google.cloud.pubsub_v1.subscriber.scheduler.ThreadScheduler(executor=None)[source]¶
- A thread pool-based scheduler. It must not be shared across
SubscriberClients.
This scheduler is useful in typical I/O-bound message processing.
- Parameters
executor (concurrent.futures.ThreadPoolExecutor) – An optional executor to use. If not specified, a default one will be created.
- property queue¶
A thread-safe queue used for communication between callbacks and the scheduling thread.
- Type
Queue
- schedule(callback, *args, **kwargs)[source]¶
Schedule the callback to be called asynchronously in a thread pool.
- Parameters
callback (Callable) – The function to call.
args – Positional arguments passed to the function.
kwargs – Key-word arguments passed to the function.
- Returns
None
- shutdown(await_msg_callbacks=False)[source]¶
Shut down the scheduler and immediately end all pending callbacks.
- Parameters
await_msg_callbacks (bool) – If
True
, the method will block until all currently executing executor threads are done processing. IfFalse
(default), the method will not wait for the currently running threads to complete.- Returns
The messages submitted to the scheduler that were not yet dispatched to their callbacks. It is assumed that each message was submitted to the scheduler as the first positional argument to the provided callback.
- Return type
List[pubsub_v1.subscriber.message.Message]