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 lib/active_job/queue_adapters/delayed_job_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def enqueue_at(job, timestamp)
delayed_job
end

def stopping?
Delayed::Worker.stop?
end

class JobWrapper
attr_accessor :job_data

Expand Down
14 changes: 11 additions & 3 deletions lib/delayed/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def self.reset
# (perhaps to inspect the reason for the failure), set this to false.
self.destroy_failed_jobs = true

# By default, Signals INT and TERM set @exit, and the worker exits upon completion of the current job.
# By default, Signals INT and TERM set @@exit, and the worker exits upon completion of the current job.
# If you would prefer to raise a SignalException and exit immediately you can use this.
# Be aware daemons uses TERM to stop and restart
# false - No exceptions will be raised
Expand Down Expand Up @@ -196,14 +196,22 @@ def start # rubocop:disable CyclomaticComplexity, PerceivedComplexity
end
end

def stop
def self.stop
@exit = true
end

def stop?
def stop
self.class.stop
end

def self.stop?
!!@exit
end

def stop?
self.class.stop?
end

# Do num jobs and return stats on success/failure.
# Exit early if interrupted.
def work_off(num = 100)
Expand Down
8 changes: 8 additions & 0 deletions spec/active_job_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ def perform(message)

expect(JobBuffer.values).to eq(%w[2 1])
end

it 'adapter stopping? reflects worker stop?' do
adapter = ActiveJob::QueueAdapters::DelayedJobAdapter.new

expect(adapter.stopping?).to eq(false)
worker.stop
expect(adapter.stopping?).to eq(true)
end
end