You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to add error handling for an async job. I found a recommendation in the repository to use Telegram::Bot::Client.default_async_job.class_eval in an initializer. However, the following code in my initializer:
Telegram::Bot::Client.default_async_job.class_eval do
rescue_from Telegram::Bot::Forbidden do |error|
Rails.logger.error("Telegram::Bot::Forbidden error: #{error.message}")
end
end
causes the application to crash on startup with the following error:
~/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/telegram-bot-0.16.7/lib/telegram/bot/async.rb:61:in 'Telegram::Bot::Async::ClassMethods#default_async_job': Define ApplicationJob class or setup #async= with custom job class (RuntimeError)
from ~/project/config/initializers/telegram.rb
In my Rails app, the ApplicationJob class is defined.
Rails 8.0.1
Ruby 3.4.1
Currently, I have added rescue_from to my ApplicationJob, but I would like to move it to a separate file, ideally in the initializer.
What is the recommended way to configure error handling in an async job?
The text was updated successfully, but these errors were encountered:
Hey, I think rails run initializers before loading classes in ./app. I'm not familiar with Rails 8 bootstrap process, but in older versions it was possible to register finalizers with Rails.application.config.to_prepare. Finalizer should have access to all app classes.
I want to add error handling for an async job. I found a recommendation in the repository to use Telegram::Bot::Client.default_async_job.class_eval in an initializer. However, the following code in my initializer:
causes the application to crash on startup with the following error:
In my Rails app, the
ApplicationJob
class is defined.Rails 8.0.1
Ruby 3.4.1
Currently, I have added
rescue_from
to myApplicationJob
, but I would like to move it to a separate file, ideally in the initializer.What is the recommended way to configure error handling in an async job?
The text was updated successfully, but these errors were encountered: