Commit 1a8b411813954ff4b2d046d3aa98ca3e50e9f0a3
1 parent
16929d88
Exists in
master
and in
7 other branches
Fix job reschedule
Showing
2 changed files
with
5 additions
and
2 deletions
Show diff stats
lib/proposals_discussion_plugin/ranking_job.rb
| ... | ... | @@ -4,6 +4,9 @@ class ProposalsDiscussionPlugin::RankingJob |
| 4 | 4 | ProposalsDiscussionPlugin::Topic.find_each do |topic| |
| 5 | 5 | ProposalsDiscussionPlugin::RankingJob::TopicRankingJob.new(topic.id).schedule |
| 6 | 6 | end |
| 7 | + end | |
| 8 | + | |
| 9 | + def after(job) | |
| 7 | 10 | schedule(30.minutes.from_now) |
| 8 | 11 | end |
| 9 | 12 | |
| ... | ... | @@ -12,7 +15,7 @@ class ProposalsDiscussionPlugin::RankingJob |
| 12 | 15 | end |
| 13 | 16 | |
| 14 | 17 | def self.find_job |
| 15 | - Delayed::Job.by_handler("--- !ruby/object:ProposalsDiscussionPlugin::RankingJob {}\n") | |
| 18 | + Delayed::Job.by_handler("--- !ruby/object:ProposalsDiscussionPlugin::RankingJob {}\n").where('locked_at IS NULL') | |
| 16 | 19 | end |
| 17 | 20 | |
| 18 | 21 | ... | ... |
test/unit/ranking_job_test.rb
| ... | ... | @@ -15,6 +15,7 @@ class RankingJobTest < ActiveSupport::TestCase |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 17 | should 'do not create duplicated ranking job' do |
| 18 | + Delayed::Job.destroy_all | |
| 18 | 19 | job.schedule |
| 19 | 20 | job.schedule |
| 20 | 21 | assert_equal 1, job.class.find_job.count |
| ... | ... | @@ -27,7 +28,6 @@ class RankingJobTest < ActiveSupport::TestCase |
| 27 | 28 | |
| 28 | 29 | should 'reschedule job when performed' do |
| 29 | 30 | process_delayed_job_queue |
| 30 | - job.perform | |
| 31 | 31 | new_job = job.class.find_job.first |
| 32 | 32 | assert new_job.present? |
| 33 | 33 | assert new_job.run_at > 20.minutes.from_now | ... | ... |