Skip to content

Commit

Permalink
Move some logic to the model
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Sep 11, 2021
1 parent 44fdd68 commit ec3b1eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/rescan_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions app/models/rescan_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/tasks/rescan.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ec3b1eb

Please sign in to comment.