Featured image

One common problem when working with background tasks in Rails is ensuring that the task queue itself is configured and functioning correctly. For this purpose, I always create a test job that simply writes a test message to the log:

class CheckJob < ApplicationJob
  queue_as :default

  def perform
    logger = Logger.new(Rails.root.join('log', 'check.log'), level: :info)
    logger.info('OK')
  end
end

Next, I run it in the console, for example like this:

bin/rails r 'CheckJob.perform_later'

This check can also be extended by adding execution of this task to the cron using the whenever gem:

every 30.minutes do
  runner 'CheckJob.perform_later'
end

And of course, you can not only write a message to the log, but also send a notification to your monitoring system.