From 33d292e9810faeb0a038d6a3df3881411183e28c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 24 Feb 2024 16:57:26 +0000 Subject: [PATCH] Move scheduling of trace import and destruction to the model --- app/controllers/api/traces_controller.rb | 4 ++-- app/controllers/traces_controller.rb | 4 ++-- app/models/trace.rb | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/traces_controller.rb b/app/controllers/api/traces_controller.rb index b66aead38..956bcde6e 100644 --- a/app/controllers/api/traces_controller.rb +++ b/app/controllers/api/traces_controller.rb @@ -35,7 +35,7 @@ module Api trace = do_create(params[:file], tags, description, visibility) if trace.id - TraceImporterJob.perform_later(trace) + trace.schedule_import render :plain => trace.id.to_s elsif trace.valid? head :internal_server_error @@ -66,7 +66,7 @@ module Api if trace.user == current_user trace.visible = false trace.save! - TraceDestroyerJob.perform_later(trace) + trace.schedule_destruction head :ok else diff --git a/app/controllers/traces_controller.rb b/app/controllers/traces_controller.rb index 242f8113c..df6337147 100644 --- a/app/controllers/traces_controller.rb +++ b/app/controllers/traces_controller.rb @@ -126,7 +126,7 @@ class TracesController < ApplicationController flash[:notice] = t ".trace_uploaded" flash[:warning] = t ".traces_waiting", :count => current_user.traces.where(:inserted => false).count if current_user.traces.where(:inserted => false).count > 4 - TraceImporterJob.perform_later(@trace) + @trace.schedule_import redirect_to :action => :index, :display_name => current_user.display_name else flash[:error] = t(".upload_failed") if @trace.valid? @@ -176,7 +176,7 @@ class TracesController < ApplicationController trace.visible = false trace.save flash[:notice] = t ".scheduled_for_deletion" - TraceDestroyerJob.perform_later(trace) + trace.schedule_destruction redirect_to :action => :index, :display_name => trace.user.display_name end rescue ActiveRecord::RecordNotFound diff --git a/app/models/trace.rb b/app/models/trace.rb index 2411fb9b7..be5d0a631 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -267,6 +267,14 @@ class Trace < ApplicationRecord end end + def schedule_import + TraceImporterJob.perform_later(self) + end + + def schedule_destruction + TraceDestroyerJob.perform_later(self) + end + private def content_type(file) -- 2.39.5