Move scheduling of trace import and destruction to the model
This commit is contained in:
parent
4c029873bb
commit
33d292e981
3 changed files with 12 additions and 4 deletions
|
@ -35,7 +35,7 @@ module Api
|
||||||
trace = do_create(params[:file], tags, description, visibility)
|
trace = do_create(params[:file], tags, description, visibility)
|
||||||
|
|
||||||
if trace.id
|
if trace.id
|
||||||
TraceImporterJob.perform_later(trace)
|
trace.schedule_import
|
||||||
render :plain => trace.id.to_s
|
render :plain => trace.id.to_s
|
||||||
elsif trace.valid?
|
elsif trace.valid?
|
||||||
head :internal_server_error
|
head :internal_server_error
|
||||||
|
@ -66,7 +66,7 @@ module Api
|
||||||
if trace.user == current_user
|
if trace.user == current_user
|
||||||
trace.visible = false
|
trace.visible = false
|
||||||
trace.save!
|
trace.save!
|
||||||
TraceDestroyerJob.perform_later(trace)
|
trace.schedule_destruction
|
||||||
|
|
||||||
head :ok
|
head :ok
|
||||||
else
|
else
|
||||||
|
|
|
@ -126,7 +126,7 @@ class TracesController < ApplicationController
|
||||||
flash[:notice] = t ".trace_uploaded"
|
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
|
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
|
redirect_to :action => :index, :display_name => current_user.display_name
|
||||||
else
|
else
|
||||||
flash[:error] = t(".upload_failed") if @trace.valid?
|
flash[:error] = t(".upload_failed") if @trace.valid?
|
||||||
|
@ -176,7 +176,7 @@ class TracesController < ApplicationController
|
||||||
trace.visible = false
|
trace.visible = false
|
||||||
trace.save
|
trace.save
|
||||||
flash[:notice] = t ".scheduled_for_deletion"
|
flash[:notice] = t ".scheduled_for_deletion"
|
||||||
TraceDestroyerJob.perform_later(trace)
|
trace.schedule_destruction
|
||||||
redirect_to :action => :index, :display_name => trace.user.display_name
|
redirect_to :action => :index, :display_name => trace.user.display_name
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|
|
@ -267,6 +267,14 @@ class Trace < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def schedule_import
|
||||||
|
TraceImporterJob.perform_later(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
def schedule_destruction
|
||||||
|
TraceDestroyerJob.perform_later(self)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def content_type(file)
|
def content_type(file)
|
||||||
|
|
Loading…
Add table
Reference in a new issue