-
I use jobs to perform unique short-to-medium-running tasks. The tasks are not just some background stuff, but something a user can observe. Yes, I am aware river API does not let me do that, but I have no problem with doing that myself. Just wanted to ask if that's a good idea and what are the chances of me breaking river job processing logic if I do so. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @atoi, good question. If you’re going to do this yourself anyway (presumably as a query invoked within the job) the safer thing to do is probably to update the job’s You can use jsonb operators to safely access/set subfields within your json structure. Up to you of course not to accidentally clobber your existing args 😆 As long as your args struct includes something like a A more formal way of doing this would be to have your own table for these operations where you record & coordinate their progress, although sometimes this lighter weight option is ok too. An example of what this could look like: say you were zipping up a bunch of files for the user to download. If you had another table like There’s no real risk in affecting job processing with any of these options, though, as long as you don’t hold open a super long transaction on the row or forget to close one. Best to make sure you have the appropriate default transaction timeout set on your pgxpool just in case your worker dies midway through the update. |
Beta Was this translation helpful? Give feedback.
Hi @atoi, good question. If you’re going to do this yourself anyway (presumably as a query invoked within the job) the safer thing to do is probably to update the job’s
args
instead. That also feels more appropriate in this case because it sounds like this is a job-specific value that you’re tracking, whereas metadata is going to be used more for layered on functionality that isn’t job-specific.You can use jsonb operators to safely access/set subfields within your json structure. Up to you of course not to accidentally clobber your existing args 😆 As long as your args struct includes something like a
progress
field you should be able to safely update it at the end of the job before retur…