Skip to content

Job Event Delegate Hooks

Compare
Choose a tag to compare
@tanner0101 tanner0101 released this 11 Oct 22:35
c562842
This patch was authored and released by @jdmcd.

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