Comments (5)
hmmm. I just doublechecked and it seems like the retry_on
handler will be called after the perform callbacks:
I'm not sure, though, in what order Active Job callbacks run. Could you try defining your around_perform
before you include GoodJob::ActiveJobExtensions::InterruptErrors
. That itself is an around_perform
:
good_job/lib/good_job/active_job_extensions/interrupt_errors.rb
Lines 8 to 12 in fbd1a5b
from good_job.
Aha, found it:
Calls the before and around callbacks in the order they were set
So if I'm understanding this correctly because these are wrapping, you'll want your own custom around_perform
wrapper to be invoked before you include GoodJob::ActiveJobExtensions::InterruptErrors
.
If that works, that might be an nice note to add to the Readme.
from good_job.
I think the reordering of callbacks does allow me to rescue the interrupt error but it also seems as if it's the second execution that is raising the exception (that I can now rescue). Does that make sense? I think I need to be able to rescue (run something) when the first execution is shutting down... 🤔
from good_job.
Oh! Yes, the InterruptError is only invoked on the 2nd execution because the first execution was interrupted (SIGKILL).
You can't call code during a SIGKILL. The best you can do is put your code in an ensure
.
Unless I'm misunderstanding the circumstances under which your job is being interrupted.
from good_job.
Thank you! I think I have something working:
around_perform do |_job, block|
# slug and monitor configs are irrelevant for this example but they exist :)
check_in_id = Sentry.capture_check_in(slug, :in_progress, monitor_config:)
start = Sentry.utc_now.to_i
result = :ok
begin
block.call
rescue StandardError
result = :error
raise
ensure
duration = Sentry.utc_now.to_i - start
Sentry.capture_check_in(
slug,
result,
check_in_id:,
duration:,
monitor_config:,
)
end
end
This does require setting a shutdown_timeout
that is lower than the grace period or timeout of the system that runs the ruby process - eg. I believe kubernetes will have a default grace period of 30 seconds.
Rails.application.configure do
...
# Wait 20 seconds for jobs to finish before shutting down. The kubernetes grace
# period is 30 seconds so forcing a shutdown after 20 seconds will allow good_job
# to handle the shutdown somewhat gracefully.
config.good_job.shutdown_timeout = 20
end
I also think my attempts to reproduce production-behaviour locally was flawed: I was using foreman
which has a default timeout of 5 seconds before sending SIGKILL
so until I set config.good_job.shutdown_timeout = 1
my ensure
block would not run.
Anyways - I believe this is working. Thanks for a great gem and your quick support :)
from good_job.
Related Issues (20)
- RuntimeError when running good_job executable after updating v3 -> v4 HOT 4
- Unhandled `GoodJob::AdvisoryLockable::RecordAlreadyAdvisoryLockedError` errors HOT 2
- Do not take an advisory lock on the process in the notifier in the production environment
- Using Good Job to track all ActiveJob executions, even those with `perform_now`
- Batch callback job not enqueued after success of retried job HOT 2
- Dynamic creation of CronEntries HOT 2
- Searching for an integer type argument (on the dashboard) does not yeild any results HOT 1
- Proposal - A better way of managing errors through the GoodJob UI HOT 3
- Edge rails changes breaking binding commits HOT 2
- `perform_limit` and `perform_throttle` don't work both HOT 5
- Issue with active_record.strict_loading_by_default
- Rails 7.2.1 breaks enqueuing without enqueue_after_transaction_commit? method on queue adapter HOT 5
- Question about GoodJob Batches in tests HOT 7
- GoodJob Timezone Day Light Savings HOT 4
- bin/rails g good_job:install fails HOT 1
- Configuring connection pool in external mode HOT 3
- Cron jobs can be missed if deploys are timed just right HOT 7
- Undefined method `unhandled_error` for nil HOT 3
- Process hanging around after container stopped
- Multiple same values in cron_keys_disabled, cron_keys_enabled in good_job_settings table HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from good_job.