vapor / queues

A queue system for Vapor.
MIT License
169 stars 41 forks source link

Job Event Delegate Hooks #87

Closed jdmcd closed 4 years ago

jdmcd commented 4 years ago

This release adds a protocol called JobEventDelegate which allows ends users to "hook" into the status of jobs that are being run. Each notification hook can specify a success handler, an error handler, or both.

To get started, conform an object to JobEventDelegate and implement any of the methods you'd like:

struct MyEventDelegate: JobEventDelegate {
    public func dispatched(job: JobEventData, eventLoop: EventLoop) -> EventLoopFuture<Void> {
        eventLoop.future()
    }

    public func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
        eventLoop.future()
    }

    public func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
        eventLoop.future()
    }

    public func error(jobId: String, error: Error, eventLoop: EventLoop) -> EventLoopFuture<Void> {
        eventLoop.future()
    }
}

Then, add it in your configuration file:

app.queues.add(MyEventDelegate())

This PR also adds a bunch of trace logging for better debugging

jdmcd commented 4 years ago

An example implementation of this is here: https://github.com/vapor-community/queues-database-hooks and we have it working nicely inside of our production application as well!

tanner0101 commented 4 years ago

These changes are now available in 1.5.0