]> git.openstreetmap.org Git - rails.git/commitdiff
Move scheduling of trace import and destruction to the model
authorTom Hughes <tom@compton.nu>
Sat, 24 Feb 2024 16:57:26 +0000 (16:57 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 24 Feb 2024 17:07:38 +0000 (17:07 +0000)
app/controllers/api/traces_controller.rb
app/controllers/traces_controller.rb
app/models/trace.rb

index b66aead38e1506e3afe3390da38c28853ace81e6..956bcde6e82dccabb23e022919d0d87673e74ec3 100644 (file)
@@ -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
index 242f8113c2783430b8b67cffadc34b0b71e95ac1..df6337147566538b89d9fa7b3c76f36b127ce182 100644 (file)
@@ -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
index 2411fb9b7a3c56c2f2adc57787a6194f83058c51..be5d0a6318c0219c11c1c3499daaab3411cd86cd 100644 (file)
@@ -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)