ActiveJob rescue_from returning success without raise and fail
up vote
0
down vote
favorite
I'm trying to catch some errors in my ApplicationJob
, but I don't want this errors to raise exceptions(and return failed job execution), but I want certain errors to be ignored(which basically returns success).
I can accomplish this using regular begin-rescue
in every job individually, but I want to share this rescues between multiple jobs.
The issue is that rescue_from
catches the error but raises the error anyway, and the job fails on the execution.
application_job.rb
class ApplicationJob < ActiveJob::Base
rescue_from StandardError do |exception|
puts "Rescuing"
true
end
end
test_job.rb
class TestJob < ApplicationJob
def perform(*args)
raise ActiveResource::ResourceNotFound, "Wow"
end
end
Log when I execute the job:
Performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default)
Error performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default) in 1.03ms: ActiveResource::ResourceNotFound (Failed.):
...
.../.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
-e:1:in `<main>'
Rescuing
=> #<ActiveResource::ResourceNotFound: Failed.>
ruby ruby-on-rails-5 rails-activejob
add a comment |
up vote
0
down vote
favorite
I'm trying to catch some errors in my ApplicationJob
, but I don't want this errors to raise exceptions(and return failed job execution), but I want certain errors to be ignored(which basically returns success).
I can accomplish this using regular begin-rescue
in every job individually, but I want to share this rescues between multiple jobs.
The issue is that rescue_from
catches the error but raises the error anyway, and the job fails on the execution.
application_job.rb
class ApplicationJob < ActiveJob::Base
rescue_from StandardError do |exception|
puts "Rescuing"
true
end
end
test_job.rb
class TestJob < ApplicationJob
def perform(*args)
raise ActiveResource::ResourceNotFound, "Wow"
end
end
Log when I execute the job:
Performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default)
Error performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default) in 1.03ms: ActiveResource::ResourceNotFound (Failed.):
...
.../.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
-e:1:in `<main>'
Rescuing
=> #<ActiveResource::ResourceNotFound: Failed.>
ruby ruby-on-rails-5 rails-activejob
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to catch some errors in my ApplicationJob
, but I don't want this errors to raise exceptions(and return failed job execution), but I want certain errors to be ignored(which basically returns success).
I can accomplish this using regular begin-rescue
in every job individually, but I want to share this rescues between multiple jobs.
The issue is that rescue_from
catches the error but raises the error anyway, and the job fails on the execution.
application_job.rb
class ApplicationJob < ActiveJob::Base
rescue_from StandardError do |exception|
puts "Rescuing"
true
end
end
test_job.rb
class TestJob < ApplicationJob
def perform(*args)
raise ActiveResource::ResourceNotFound, "Wow"
end
end
Log when I execute the job:
Performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default)
Error performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default) in 1.03ms: ActiveResource::ResourceNotFound (Failed.):
...
.../.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
-e:1:in `<main>'
Rescuing
=> #<ActiveResource::ResourceNotFound: Failed.>
ruby ruby-on-rails-5 rails-activejob
I'm trying to catch some errors in my ApplicationJob
, but I don't want this errors to raise exceptions(and return failed job execution), but I want certain errors to be ignored(which basically returns success).
I can accomplish this using regular begin-rescue
in every job individually, but I want to share this rescues between multiple jobs.
The issue is that rescue_from
catches the error but raises the error anyway, and the job fails on the execution.
application_job.rb
class ApplicationJob < ActiveJob::Base
rescue_from StandardError do |exception|
puts "Rescuing"
true
end
end
test_job.rb
class TestJob < ApplicationJob
def perform(*args)
raise ActiveResource::ResourceNotFound, "Wow"
end
end
Log when I execute the job:
Performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default)
Error performing TestJob (Job ID: fd58cbd5-eb03-4fdc-8301-1ea70a9b1d8b) from Async(default) in 1.03ms: ActiveResource::ResourceNotFound (Failed.):
...
.../.rvm/rubies/ruby-2.4.4/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
-e:1:in `<main>'
Rescuing
=> #<ActiveResource::ResourceNotFound: Failed.>
ruby ruby-on-rails-5 rails-activejob
ruby ruby-on-rails-5 rails-activejob
asked Nov 19 at 12:28
overallduka
8661425
8661425
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374655%2factivejob-rescue-from-returning-success-without-raise-and-fail%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown