diff --git a/app/controllers/rescan_controller.rb b/app/controllers/rescan_controller.rb index d0162f8e..ba9909c2 100644 --- a/app/controllers/rescan_controller.rb +++ b/app/controllers/rescan_controller.rb @@ -6,14 +6,14 @@ def show end def start - @rescan.delay(queue: :rescans).run + @rescan.schedule render json: @rescan end private def set_rescan - @rescan = RescanRunner.first || RescanRunner.create + @rescan = RescanRunner.instance authorize @rescan end end diff --git a/app/models/rescan_runner.rb b/app/models/rescan_runner.rb index 4314c8cc..edd4aa1b 100644 --- a/app/models/rescan_runner.rb +++ b/app/models/rescan_runner.rb @@ -11,6 +11,14 @@ # class RescanRunner < ApplicationRecord + def self.instance + RescanRunner.first || RescanRunner.create + end + + def schedule + delay(queue: :rescans).run + end + def run # rubocop:disable Rails/SkipsModelValidations # RescanRunner doesn't have validations, and we need to use update_all to use it's atomicity diff --git a/lib/tasks/rescan.rake b/lib/tasks/rescan.rake index 2da73ae3..6be5823c 100644 --- a/lib/tasks/rescan.rake +++ b/lib/tasks/rescan.rake @@ -1,6 +1,5 @@ namespace :rescan do task start: :environment do - rescan = RescanRunner.first || RescanRunner.create - rescan.delay(queue: :rescans).run + RescanRunner.instance.start_delayed end end