Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ bin/jobs -c config/calendar.yml

You can also skip the scheduler process by setting the environment variable `SOLID_QUEUE_SKIP_RECURRING=true`. This is useful for environments like staging, review apps, or development where you don't want any recurring jobs to run. This is equivalent to using the `--skip-recurring` option with `bin/jobs`.

To run **only** the scheduler (no workers or dispatchers)—for example to isolate recurring tasks on a dedicated process—set `SOLID_QUEUE_ONLY_RECURRING=true` or use the `--only-recurring` option with `bin/jobs`.

This is what this configuration looks like:

```yml
Expand Down Expand Up @@ -709,6 +711,8 @@ bin/jobs --recurring_schedule_file=config/schedule.yml

You can completely disable recurring tasks by setting the environment variable `SOLID_QUEUE_SKIP_RECURRING=true` or by using the `--skip-recurring` option with `bin/jobs`.

To run only the scheduler (no workers or dispatchers), set `SOLID_QUEUE_ONLY_RECURRING=true` or use `--only-recurring` with `bin/jobs`.

The configuration itself looks like this:

```yml
Expand Down
4 changes: 4 additions & 0 deletions lib/solid_queue/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Cli < Thor
desc: "Whether to skip recurring tasks scheduling",
banner: "SOLID_QUEUE_SKIP_RECURRING"

class_option :only_recurring, type: :boolean,
desc: "Whether to run only the scheduler process for recurring tasks",
banner: "SOLID_QUEUE_ONLY_RECURRING"

def self.exit_on_failure?
true
end
Expand Down
10 changes: 9 additions & 1 deletion lib/solid_queue/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def initialize(**options)
end

def configured_processes
if only_work? then workers
if only_work?
workers
elsif only_recurring?
schedulers
else
dispatchers + workers + schedulers
end
Expand Down Expand Up @@ -126,6 +129,7 @@ def default_options
recurring_schedule_file: Rails.root.join(ENV["SOLID_QUEUE_RECURRING_SCHEDULE"] || DEFAULT_RECURRING_SCHEDULE_FILE_PATH),
only_work: false,
only_dispatch: false,
only_recurring: ActiveModel::Type::Boolean.new.cast(ENV["SOLID_QUEUE_ONLY_RECURRING"]),
skip_recurring: ActiveModel::Type::Boolean.new.cast(ENV["SOLID_QUEUE_SKIP_RECURRING"])
}
end
Expand All @@ -142,6 +146,10 @@ def only_dispatch?
options[:only_dispatch]
end

def only_recurring?
options[:only_recurring]
end

def skip_recurring_tasks?
options[:skip_recurring] || only_work?
end
Expand Down
16 changes: 16 additions & 0 deletions test/unit/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ class CliTest < ActiveSupport::TestCase
end
end

test "only_recurring option runs just the scheduler" do
config = configuration_from_cli(only_recurring: true)

assert_equal 1, config.configured_processes.count
assert_equal :scheduler, config.configured_processes.first.kind
end

test "only_recurring respects SOLID_QUEUE_ONLY_RECURRING env var" do
with_env("SOLID_QUEUE_ONLY_RECURRING" => "true") do
config = configuration_from_cli

assert_equal 1, config.configured_processes.count
assert_equal :scheduler, config.configured_processes.first.kind
end
end

test "check exits 0 and prints OK message for a valid configuration" do
out, err = capture_io do
assert_nothing_raised { SolidQueue::Cli.start([ "check", "--skip-recurring" ]) }
Expand Down
39 changes: 39 additions & 0 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,45 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_processes configuration, :dispatcher, 1, polling_interval: 0.1, recurring_tasks: nil
end

test "only_recurring runs just the scheduler process" do
configuration = SolidQueue::Configuration.new(only_recurring: true)

assert_equal 1, configuration.configured_processes.count
assert_processes configuration, :scheduler, 1
assert_processes configuration, :worker, 0
assert_processes configuration, :dispatcher, 0
assert configuration.valid?
end

test "only_recurring ignores workers and dispatchers from the config file" do
configuration = SolidQueue::Configuration.new(only_recurring: true)

assert_processes configuration, :worker, 0
assert_processes configuration, :dispatcher, 0
assert_processes configuration, :scheduler, 1

scheduler = configuration.configured_processes.first.instantiate
assert_has_recurring_task scheduler, key: "periodic_store_result", class_name: "StoreResultJob", schedule: "every second"
end

test "only_recurring when SOLID_QUEUE_ONLY_RECURRING environment variable is set" do
with_env("SOLID_QUEUE_ONLY_RECURRING" => "true") do
configuration = SolidQueue::Configuration.new

assert_equal 1, configuration.configured_processes.count
assert_processes configuration, :scheduler, 1
assert_processes configuration, :worker, 0
assert_processes configuration, :dispatcher, 0
end
end

test "only_recurring with skip_recurring is invalid" do
configuration = SolidQueue::Configuration.new(only_recurring: true, skip_recurring: true)

assert_not configuration.valid?
assert_equal [ "No processes configured" ], configuration.errors.full_messages
end

test "skip recurring tasks when SOLID_QUEUE_SKIP_RECURRING environment variable is set" do
with_env("SOLID_QUEUE_SKIP_RECURRING" => "true") do
configuration = SolidQueue::Configuration.new(dispatchers: [ { polling_interval: 0.1 } ])
Expand Down
Loading