Some changes related to errors when enqueuing jobs:
~Raise ActiveJob::EnqueueError on ActiveRecordError on enqueuing, as Active Job expects and handles.~ Raise SolidQueue::Job::EnqueueError on ActiveRecordError on enqueuing. The reason is that we can't easily control what happens when something goes wrong on enqueuing if the jobs are enqueued by Rails or other gems (eg. Turbo::Streams::BroadcastJob, ActiveStorage::AnalyzeJob...), because the only way is to check what the return value of the call to perform_later is, or to pass a block to that method to fetch the error that gets set in enqueue_error. In this way at least the error will bubble up and you can rescue or let it be raised.
Fix bug when enqueuing the job for a recurring task fails (reported in #251): as perform_later in this case returns false, which crashes when we try to access job_id on it. perform_later returns the job instance with successfully_enqueued set to true when it goes well, but false when it fails. You can provide a block and the job instance with successfully_enqueued set to false, and an error set in enqueue_error is yielded to that block, but it's not returned.
At first, I tried to make this a bit more sophisticated, passing a block to get the job and populate the instrumentation payload with it, but the code was getting quite cumbersome, and the error is instrumented by Active Job anyway, so in the end I just simplified this and opted for handling this case to avoid crashing.
Some changes related to errors when enqueuing jobs:
ActiveJob::EnqueueError
onActiveRecordError
on enqueuing, as Active Job expects and handles.~ RaiseSolidQueue::Job::EnqueueError
onActiveRecordError
on enqueuing. The reason is that we can't easily control what happens when something goes wrong on enqueuing if the jobs are enqueued by Rails or other gems (eg.Turbo::Streams::BroadcastJob
,ActiveStorage::AnalyzeJob
...), because the only way is to check what the return value of the call toperform_later
is, or to pass a block to that method to fetch the error that gets set inenqueue_error
. In this way at least the error will bubble up and you can rescue or let it be raised.perform_later
in this case returnsfalse
, which crashes when we try to accessjob_id
on it.perform_later
returns the job instance withsuccessfully_enqueued
set to true when it goes well, butfalse
when it fails. You can provide a block and the job instance withsuccessfully_enqueued
set tofalse
, and an error set inenqueue_error
is yielded to that block, but it's not returned. At first, I tried to make this a bit more sophisticated, passing a block to get the job and populate the instrumentation payload with it, but the code was getting quite cumbersome, and the error is instrumented by Active Job anyway, so in the end I just simplified this and opted for handling this case to avoid crashing.