vapor/queues

improving configuration api

tanner0101 opened this issue · 2 comments

This is what a min-viable setup for vapor + jobs looks like currently:

let app = Application(environment: env)
app.provider(JobsProvider())
app.register(JobsDriver.self) { app in
    return TestDriver(on: app.make())
}
app.register(extension: JobsConfiguration.self) { jobs, app in
    jobs.add(FooJob())
}
app.get("foo") { req in
    return req.jobs.dispatch(FooJob.Data(foo: "bar"))
        .map { "done" }
}
return app

Not bad at all, but I have some ideas. What about something like this:

let app = Application(environment: env)
app.provider(JobsProvider())

app.jobs.driver(TestDriver())
app.jobs.add(FooJob())
app.jobs.add(BarJob())
app.jobs.add(QuxJob())

app.get("foo") { req in
    return req.jobs.dispatch(FooJob.self, .init(foo: "bar"))
        .map { "done" }
}
return app
jdmcd commented

I agree, I think this would be really nice.

jdmcd commented

Closed in #43