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

Feature: StopAndPauseJobsWorkRake : stop or pause the jobs:work rake … #1186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/delayed/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,12 @@ def handle_failed_job(job, error)
# Run the next job we can get an exclusive lock on.
# If no jobs are left we return nil
def reserve_and_run_one_job
job = reserve_job
self.class.lifecycle.run_callbacks(:perform, self, job) { run(job) } if job
stop_worker = end_rake_task if File.file?('stop_dj_worker.txt')
pause_worker = pause_rake_task if File.file?('pause_dj_worker.txt')
unless stop_worker || pause_worker
job = reserve_job
self.class.lifecycle.run_callbacks(:perform, self, job) { run(job) } if job
end
end

def reserve_job
Expand All @@ -334,6 +338,19 @@ def reload!
ActionDispatch::Reloader.prepare!
end
end

def end_rake_task
puts 'killing worker task'
File.open('dj_worker_stopped.txt', 'a') { |f| f.write("#{Process.pid}\n") }
Process.kill("INT", Process.pid)
sleep(100)
true
end

def pause_rake_task
puts 'worker paused'
true
end
end
end

Expand Down