Skip to content

Commit e04c1f9

Browse files
iamradioactiverosa
authored andcommitted
Add option to skip recurring jobs via environment variable
1 parent 098a004 commit e04c1f9

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ By default, Solid Queue will try to find your configuration under `config/queue.
193193
bin/jobs -c config/calendar.yml
194194
```
195195

196+
You can also skip all recurring tasks 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`.
197+
196198
This is what this configuration looks like:
197199

198200
```yml
@@ -596,6 +598,8 @@ Solid Queue supports defining recurring tasks that run at specific times in the
596598
bin/jobs --recurring_schedule_file=config/schedule.yml
597599
```
598600

601+
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`.
602+
599603
The configuration itself looks like this:
600604

601605
```yml

lib/solid_queue/cli.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class Cli < Thor
1313
banner: "SOLID_QUEUE_RECURRING_SCHEDULE"
1414

1515
class_option :skip_recurring, type: :boolean, default: false,
16-
desc: "Whether to skip recurring tasks scheduling"
16+
desc: "Whether to skip recurring tasks scheduling",
17+
banner: "SOLID_QUEUE_SKIP_RECURRING"
1718

1819
def self.exit_on_failure?
1920
true

lib/solid_queue/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def default_options
8888
recurring_schedule_file: Rails.root.join(ENV["SOLID_QUEUE_RECURRING_SCHEDULE"] || DEFAULT_RECURRING_SCHEDULE_FILE_PATH),
8989
only_work: false,
9090
only_dispatch: false,
91-
skip_recurring: false
91+
skip_recurring: ActiveModel::Type::Boolean.new.cast(ENV["SOLID_QUEUE_SKIP_RECURRING"])
9292
}
9393
end
9494

test/test_helpers/configuration_test_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,18 @@ module ConfigurationTestHelper
44
def config_file_path(name)
55
Rails.root.join("config/#{name}.yml")
66
end
7+
8+
def with_env(env_vars)
9+
original_values = {}
10+
env_vars.each do |key, value|
11+
original_values[key] = ENV[key]
12+
ENV[key] = value
13+
end
14+
15+
yield
16+
ensure
17+
original_values.each do |key, value|
18+
ENV[key] = value
19+
end
20+
end
721
end

test/unit/configuration_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,30 @@ class ConfigurationTest < ActiveSupport::TestCase
8585
assert_processes configuration, :dispatcher, 1, polling_interval: 0.1, recurring_tasks: nil
8686
end
8787

88+
test "skip recurring tasks when SOLID_QUEUE_SKIP_RECURRING environment variable is set" do
89+
with_env("SOLID_QUEUE_SKIP_RECURRING" => "true") do
90+
configuration = SolidQueue::Configuration.new(dispatchers: [ { polling_interval: 0.1 } ])
91+
assert_processes configuration, :dispatcher, 1, polling_interval: 0.1
92+
assert_processes configuration, :scheduler, 0
93+
end
94+
end
95+
96+
test "include recurring tasks when SOLID_QUEUE_SKIP_RECURRING environment variable is false" do
97+
with_env("SOLID_QUEUE_SKIP_RECURRING" => "false") do
98+
configuration = SolidQueue::Configuration.new(dispatchers: [ { polling_interval: 0.1 } ])
99+
assert_processes configuration, :dispatcher, 1, polling_interval: 0.1
100+
assert_processes configuration, :scheduler, 1
101+
end
102+
end
103+
104+
test "include recurring tasks when SOLID_QUEUE_SKIP_RECURRING environment variable is not set" do
105+
with_env("SOLID_QUEUE_SKIP_RECURRING" => nil) do
106+
configuration = SolidQueue::Configuration.new(dispatchers: [ { polling_interval: 0.1 } ])
107+
assert_processes configuration, :dispatcher, 1, polling_interval: 0.1
108+
assert_processes configuration, :scheduler, 1
109+
end
110+
end
111+
88112
test "validate configuration" do
89113
# Valid and invalid recurring tasks
90114
configuration = SolidQueue::Configuration.new(recurring_schedule_file: config_file_path(:recurring_with_invalid))

0 commit comments

Comments
 (0)