Class: PipelinesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pipelines_controller.rb

Overview

The pipelines controller is concerned with pipelines lab processes that handle the processing of requests. This controller is concerned with those piplines that are handled internally by Sequencescape directly, not those processed by apps such as Limber. In general we have been trying to move this behaviour out of Sequencescape, but some legacy pipelines remain.

Endpoints

Some of these endpoints should probably be moved elsewhere

CRUD

  • Showing a list of available pipelines to the users (index)

  • Displaying the Pipeline inbox to users, from which they can create batches (show)

Extra

  • Activation and deactivation of the pipeline (activate/deactivate) I'm not aware of any links to this

  • Listing batches associated with a pipeline (batches) [Move to Pipelines::Batches?]

Move to RequestsController?

  • Change the priority of a request via clicking the flag in the inbox (Update priority)

Move to BatchesController?

The batches controller is already very large, but these definitely don't belong here

  • Finish a batch (finish)

  • Release a batch (release)

  • Show a batch summary (summary)

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Method Details

#activateObject


108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/pipelines_controller.rb', line 108

def activate
  @pipeline.active = true
  if @pipeline.save
    flash[:notice] = 'Pipeline activated'
    redirect_to pipelines_path
  else
    flash[:notice] = 'Failed to activate pipeline'
    redirect_to pipeline_path(@pipeline)
  end
end

#batchesObject


130
131
132
# File 'app/controllers/pipelines_controller.rb', line 130

def batches
  @batches = @pipeline.batches.order(id: :desc).page(params[:page])
end

#deactivateObject


119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/pipelines_controller.rb', line 119

def deactivate
  @pipeline.active = false
  if @pipeline.save
    flash[:notice] = 'Pipeline deactivated'
    redirect_to pipelines_path
  else
    flash[:notice] = 'Failed to deactivate pipeline'
    redirect_to pipeline_path(@pipeline)
  end
end

#finishObject


91
92
93
94
95
96
# File 'app/controllers/pipelines_controller.rb', line 91

def finish
  ActiveRecord::Base.transaction { @batch.complete!(current_user) }
rescue ActiveRecord::RecordInvalid => e
  flash[:error] = e.record.errors.full_messages
  redirect_to(url_for(controller: 'batches', action: 'show', id: @batch.id))
end

#indexObject


31
32
33
34
35
36
37
38
39
# File 'app/controllers/pipelines_controller.rb', line 31

def index
  @pipelines = Pipeline.active.internally_managed.alphabetical
  @grouping = @pipelines.group_by(&:group_name)

  respond_to do |format|
    format.html
    format.xml { render xml: @pipelines.to_xml }
  end
end

#releaseObject


98
99
100
101
102
103
104
105
106
# File 'app/controllers/pipelines_controller.rb', line 98

def release
  ActiveRecord::Base.transaction do
    @batch = Batch.find(params[:id])
    @batch.release!(current_user)
  end

  flash[:notice] = 'Batch released!'
  redirect_to controller: 'batches', action: 'show', id: @batch.id
end

#showObject

rubocop:todo Metrics/MethodLength


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/pipelines_controller.rb', line 42

def show # rubocop:todo Metrics/AbcSize
  expires_now
  @show_held_requests = (params[:view] == 'all')

  @pending_batches = @pipeline.batches.pending_for_ui.includes_for_ui
  @batches_in_progress = @pipeline.batches.in_progress_for_ui.includes_for_ui
  @completed_batches = @pipeline.batches.completed_for_ui.includes_for_ui
  @released_batches = @pipeline.batches.released_for_ui.includes_for_ui
  @failed_batches = @pipeline.batches.failed_for_ui.includes_for_ui

  @batches = @last5_batches = @pipeline.batches.latest_first.includes_for_ui

  @information_types = @pipeline.request_information_types.shown_in_inbox

  if @pipeline.group_by_parent?
    Rails.logger.info('Pipeline grouped by parent')

    # We use the inbox presenter
    @inbox_presenter = Presenters::GroupedPipelineInboxPresenter.new(@pipeline, current_user, @show_held_requests)
    @requests_waiting = @inbox_presenter.requests_waiting
  elsif @pipeline.group_by_submission?
    Rails.logger.info('Pipeline grouped by submission')

    # Convert to an array now as otherwise the comments counter attempts to be too clever
    # and treats the requests like a scope. Not only does this result in a more complicated
    # query, but also an invalid one
    @requests_waiting = @pipeline.request_count_in_inbox(@show_held_requests)
    requests = @pipeline.requests_in_inbox(@show_held_requests).to_a
    @grouped_requests = requests.group_by(&:submission_id)
    @requests_comment_count = Comment.counts_for_requests(requests)
  else
    Rails.logger.info('Pipeline fallback behaviour')
    @requests_waiting = @pipeline.request_count_in_inbox(@show_held_requests)
    @requests = @pipeline.requests_in_inbox(@show_held_requests).to_a

    # We convert to an array here as otherwise rails tries to be smart and use
    # the scope in subsequent queries. Not only does it fail, but we may as
    # well fetch the result now anyway.
    @requests_comment_count = Comment.counts_for_requests(@requests)
    @requests_samples_count = Request.where(id: @requests).joins(:samples).group(:id).count
  end
end

#summaryObject

TODO:

More out of the pipelines controller

Renders the batch summary


89
# File 'app/controllers/pipelines_controller.rb', line 89

def summary; end

#update_priorityObject

to modify when next_request will be ready


135
136
137
138
139
140
141
142
143
# File 'app/controllers/pipelines_controller.rb', line 135

def update_priority
  request = Request.find(params[:request_id])
  ActiveRecord::Base.transaction do
    request.update_priority
    render plain: '', layout: false
  end
rescue ActiveRecord::RecordInvalid => e
  render plain: '', layout: false, status: :unprocessable_entity
end