I'm using Sidekiq to get some background jobs done. I am also trying to log some messages from these jobs to a log file, but I have been unable to do this simple task.
Example of the kind of job I'm running
class TestJob < ApplicationJob
queue_as :default
def perform
text = 'Print me to a file!'
Rails.logger.error "Rails.logger.info : #{text}"
logger.error "logger.info : #{text}"
end
end
Running TestJob.perform_now
, in a controller action for example, works as expected, printing the messages to the server terminal output, as well as to logs/development.log
.
But running TestJob.perform_later
doesn't print my messages. Anywhere. Not to the Sidekiq terminal, the server terminal, log files, nothing.
I tried redirecting the logs, as suggested in the Sidekiq Logging wiki. But the messages didn't get printed there either.
I feel like I might be missing something crucial.
If you build a web application you should minimize the amount of time spent responding to every user; a fast website means a happy user.
Sidekiq is an open-source framework that provides efficient background processing for Ruby applications. It uses Redis as an in-memory data structure to store all of its job and operational data. It's important to be aware that Sidekiq by default doesn't do scheduling, it only executes jobs.
Active Job is a framework for declaring jobs and making them run on a variety of queueing backends. These jobs can be everything from regularly scheduled clean-ups, to billing charges, to mailings. Anything that can be chopped up into small units of work and run in parallel, really.
Try to call Sidekiq.logger
, as in:
Sidekiq.logger.error "logger.info : #{text}"
Putting "logger.info" in the log of an error might be a little weird, but I was just taking from the example posted in the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With