Skip to content

Commit

Permalink
Add GoodJob.cli? to check if the current process was started by the…
Browse files Browse the repository at this point in the history
… `good_job` executable (#1592)
  • Loading branch information
bensheldon authored Jan 30, 2025
1 parent fdf9a01 commit e28fe17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ def self.paused?(queue: nil, job_class: nil, label: nil)
def self.paused(type = nil)
GoodJob::Setting.paused(type)
end

# Whether this process was initialized via the GoodJob executable (`$ good_job`)
# @return [Boolean]
def self.cli?
GoodJob::CLI.within_exe?
end
end

ActiveSupport.run_load_hooks(:good_job, GoodJob)
10 changes: 10 additions & 0 deletions spec/lib/good_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,14 @@ def perform(succeed: true)
expect(described_class.paused).to eq({ queues: [], job_classes: [], labels: [] })
end
end

describe '.cli?' do
it 'returns true when in a CLI environment' do
allow(GoodJob::CLI).to receive(:within_exe?).and_return(false)
expect(described_class.cli?).to be false

allow(GoodJob::CLI).to receive(:within_exe?).and_return(true)
expect(described_class.cli?).to be true
end
end
end

0 comments on commit e28fe17

Please sign in to comment.