应用程序/模型/ assessment_attempt.rb
class AssesmentAttempt
enum progress: [:not_started, :in_progress, :completed]
...
def update_progress(is_completed)
if is_completed
mark_completed
StatsUpdateWorker.perform_anync(id)
end
end
def mark_completed
self.completed!
end
end
应用程序/工人/ stats_update_worker.rb
class StatsUpdateWorker
include Sidekiq::Worker
def perform(attempt_id)
assessment_attempt = AssessmentAttempt.find_by_id(attempt_id)
unless assessment_attempt.completed?
//raise some exception
end
//do-the-action
end
end
这里,sidekiq工作者通过id找到尝试。即使在通过mark_completed
方法更新进度后调用worker之后,对象的progress字段仍将是in_progress。没有更新失败。在整个动作之后,我可以看到字段被修改为completed
。但是当sidekiq开始处理时,该字段不会更新。我该如何解决这个问题?