← Home
sidekiq

Rails Generate sidekiq:job

Reference & Command Builder

Published: 2023-07-11
Author: Harrison Broadbent
Type: Reference & Command Builder

Rails Generate Sidekiq:Job

Rails Generate Sidekiq:Job (rails g sidekiq:job) is the generator for a Sidekiq job. A Sidekiq job is similar to a regular ActiveJob job, but it's written specifically for Sidekiq (and not compatible with other job queues).

The main benefit of writing a Sidekiq job, rather than a regular ActiveJob job, is performance. Sidekiq jobs are typically much more performant than ActiveJob jobs.

A freshly generated sidekiq:job will look like this —

# app/sidekiq/example_job.rb
#
class ExampleJob
  include Sidekiq::Job
 
  def perform(*args)
    # Do something
  end
end

You'll also want to double check that as part of installing Sidekiq, you've configured it as your ActiveJob queue —

# config/application.rb
#
class Application < Rails::Application
  # ...
  config.active_job.queue_adapter = :sidekiq
end

Command Builder for rails g sidekiq:job

rails g sidekiq:job 

Job name

Generator Options

Runtime Options

# Command Options
❯ rails g sidekiq:job

Usage:
  bin/rails generate sidekiq:job NAME [options]

Options:
  [--skip-namespace], [--no-skip-namespace]              # Skip namespace (affects only isolated engines)
                                                         # Default: false
  [--skip-collision-check], [--no-skip-collision-check]  # Skip collision check
                                                         # Default: false

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

# Command Description
Description:
  This generator creates a Sidekiq Job in app/sidekiq and a corresponding test