Big refactor #2 + Jobs Jobs Jobs - #351
Conversation
| return new Proxy( | ||
| {}, | ||
| { | ||
| get: (target, key) => async (payload: Record<string, any>) => { |
There was a problem hiding this comment.
In the spirit of PostHog/plugin-scaffold#16 (review), could runIn not take target and key directly?
There was a problem hiding this comment.
Hm... we don't really use target at all, so I assume you mean payload? I mean we can have:
job.runIn(3, 'minutes', 'taskName', { task: 'payload' })... but doesn't really spark joy.
job.runIn(3, 'minutes').taskName({ task: 'payload' })Not sure, it's all very subjective :). Feel free to make some plugin and play around with alternative APIs for this.
There was a problem hiding this comment.
Alternatively, we can also flip it around:
jobs.taskName({ task: 'payload' }).runIn(3, 'minutes')
jobs.taskName({ task: 'payload' }).runNow()ba2cd35 to
cc2c699
Compare
|
All right, the last changes in this PR flip the functions around and now this is how it works: export const jobs = {
retryProcessEvent: (event, meta) => {
console.log('retrying event!', event.event)
}
}
export async function processEvent (event, { jobs }) {
if (event.properties?.hi === 'ha') {
console.log('processEvent')
// await to be sure it got enqueued, otherwise skip it and YOLO
await jobs.retryProcessEvent(event).runIn(30, 'seconds')
await jobs.retryProcessEvent(event).runNow()
await jobs.retryProcessEvent(event).runAt(new Date())
}
return event
}@yakkomajuri @Twixes would this syntax work for you? In case tests pass (this PR includes some flake fixes and other cleanup), I might merge this anyway and we can always tweak it later this week. |
yakkomajuri
left a comment
There was a problem hiding this comment.
Quite like the new syntax - also happy to merge and iterate if necessary
|
Just tested this with Amazon Aurora Serverless (thanks @fuziontech) and it actually works with it! 🎉 In any case, I'd still like to improve the layering and fallback system for these job queues. So plenty of refactoring still to come. |
| hello: (server, args) => { | ||
| return `hello ${args}!` | ||
| }, |
There was a problem hiding this comment.
Should this be in here, as just hello? Seems a bit cryptic/odd
There was a problem hiding this comment.
That can be most likely deleted. I just copied this from the previous place. Next time, as there are more refactors to come.
|
That flipped API looks pretty great 👌 @mariusandra |
…PostHog/plugin-server#351) * Rename "retry" to "jobs", improve API for scheduling jobs. * refactor jobs test * more debug for redlock * turn the job code around * add `.runAt` method * add tests for the three methods: runNow, runAt and runIn * use variable delay * fix unintentionally broken test * better ways to throw errors * log a bit more on error in tests * use graphile url for consumer, refactor queues slightly * move connect to server * silence warning for now * fix default config in GH tests
Changes
I'm also very happy to discuss changes to the API. This is the PR to do that.
Checklist