Executor
depeche_db.Executor(db_dsn)
Executor is a class that runs handlers on notifications.
Typical usage:
executor = Executor(db_dsn="postgresql://localhost:5432/mydb")
executor.register(MyRunOnNotification())
executor.run() # this will stop on SIGTERM or SIGINT
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_dsn |
str
|
DSN for the PostgreSQL database |
required |
register(handler)
Registers a handler to be run on notifications.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handler |
RunOnNotification
|
Handler to register |
required |
run()
Runs the executor.
depeche_db.RunOnNotification
Bases: Protocol
Run on notification is a protocol that allows objects to be run when a notification is received on a channel. Objects that implement this protocol can be registered with a Executor object.
Implemented by
notification_channel: str
property
Returns notification channel name.
run()
Runs the object. This method needs to return when a chunk of work has been done.
stop()
If the object's run
method has a loop, this method can be used to
exit the loop earlier.
Will be called in a separate thread.