Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GoodJob.cli? to check if the current process was started by the good_job executable #1592

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
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
Loading