Class: FlowTasksController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/templates/flow_tasks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/templates/flow_tasks_controller.rb', line 16

def create
  class_name = params.keys.detect{|k| k =~ /flow_task/}
  klass = class_name.camelize.constantize rescue FlowTask
  @flow_task = klass.new(params[class_name])
  @flow_task.user = current_user
  if @flow_task.save
    flash[:notice] = "Flow task created"
    redirect_to run_flow_task_path(@flow_task)
  else
    render :new
  end
end

#destroyObject



54
55
56
57
58
# File 'lib/generators/templates/flow_tasks_controller.rb', line 54

def destroy
  @flow_task.destroy
  flash[:notice] = "Flow task destroyed"
  redirect_to flow_tasks_path
end

#indexObject



4
5
6
# File 'lib/generators/templates/flow_tasks_controller.rb', line 4

def index
  @flow_tasks = FlowTask.order("id desc").paginate(:page => params[:page])
end

#newObject



11
12
13
14
# File 'lib/generators/templates/flow_tasks_controller.rb', line 11

def new
  klass = params[:type].camlize.constantize rescue FlowTask
  @flow_task = klass.new
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/generators/templates/flow_tasks_controller.rb', line 29

def run
  # Get the flow task id and type frmo params[:id], a composite of id and type
  flow_task_id, flow_task_type = params[:id].split /-/
  # Convert flow task type from string to Sidekiq job class
  flow_task_job = "FlowTaskJob::#{flow_task_type.camelize}".constantize
  # Set @job from params[:job]
  @job = params[:job]
  # If @job has content, check on the status of the flow task related to the job
  if @job
    @flow_task = FlowTask.find(flow_task_id.to_i)
    # Check whether the Sidekiq flow task job is still alive
    if Sidekiq::Status::failed? @job
      @flow_task.update_attribute(:error_msg, "The flow task run into system error, please contact Admin.")
    end
    @status = @flow_task.status
    @error_msg = @flow_task.error_msg if @status == "error"
    @tries = params[:tries].to_i
  # Else start the Sidekiq job for the flow task
  else
    @job = flow_task_job.perform_async(flow_task_id)
    @status = "start"
    @tries = 1
  end
end

#showObject



8
9
# File 'lib/generators/templates/flow_tasks_controller.rb', line 8

def show
end