-
Hey folks, I have a question about some nitty gritty wording in the documentation, and what a potential way forward for my architecture might be. tl;dr: InsertOpts.Pending says "... scheduled by an external update", what is that? For my usecase, I would like to "stage" a job (set the args, get a job ID). And then on user interaction (a webhook, containing the job ID), move the job from pending to available (or possibly even scheduled). The actual architecture I'm hoping to achieve here looks a bit like this: sequenceDiagram
river->>+Worker[JobA]: Work(ctx, JobA{})
Worker[JobA]->>river : Insert(ctx, JobB{}, InsertOpts{Pending: true})
river->>Worker[JobA] : JobB{ID: 43, State: "pending"}
Worker[JobA]->>externalService : Do some work, and then call back to me with "Job ID 43"
Worker[JobA]->>-river: JobComplete
externalService->>internalService : I'm complete, this was for Job ID 43
internalService->>river : Schedule JobB{ID:43}
(There's some more nuanced situations where that wouldn't even necessarily be "run JobB{ID:43} right now", but could be "run JobB{ID:43} in ten minutes", but that's minor in comparison I think) From the go docs, the comment I'm particularly highlighting:
What is intended for that "external update?" Is that something that can/should be done with the river API, or is that running Would running queries like that be "relatively stable" of an API? What about scheduling? Do I need to make sure to set both scheduled_at and state, is there any other fields, etc? Some prior dicussions that have had workaround answers, but I think haven't specifically answered this one :)
-- What I haven't tried:
I'd love if there's something I'm missing! If not, a way to expose |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @travisby, I think you’ve mostly grasped the pending state based on your prior comments. It’s a place to stage jobs that will never be worked, not until some piece of logic advances those jobs into the available or scheduled state. As for what that logic is, it’s really up to you! Your simple query to move the job into available is indeed a way to do this given you already know the job’s ID, though I would caution you to add a A more advanced usage would be for something like “I don’t want this job to run before an external event happens, and I also don’t want it to run before X time”. In that case you would want to be sure that your update query puts jobs into the I hope that helps confirm your findings! |
Beta Was this translation helpful? Give feedback.
Hi @travisby, I think you’ve mostly grasped the pending state based on your prior comments. It’s a place to stage jobs that will never be worked, not until some piece of logic advances those jobs into the available or scheduled state.
As for what that logic is, it’s really up to you! Your simple query to move the job into available is indeed a way to do this given you already know the job’s ID, though I would caution you to add a
WHERE state = ‘pending’
clause to it just to make sure you don’t accidentally mess with a job that already ran or is running.A more advanced usage would be for something like “I don’t want this job to run before an external event happens, and I also don’t want i…