Class: WorkCompletion::LabwareCompletion

Inherits:
Object
  • Object
show all
Defined in:
app/models/work_completion/labware_completion.rb

Overview

Shared behaviour of WorkCompletion::PlateCompletion and WorkCompletion::TubeCompletion

Author:

  • Genome Research Ltd.

Direct Known Subclasses

PlateCompletion, TubeCompletion

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(labware, submission_ids, work_completion) ⇒ LabwareCompletion

Returns a new instance of LabwareCompletion.



10
11
12
13
14
15
# File 'app/models/work_completion/labware_completion.rb', line 10

def initialize(labware, submission_ids, work_completion)
  @target_labware = labware
  @submission_ids = submission_ids
  @order_ids = []
  @work_completion = work_completion
end

Instance Attribute Details

#order_idsObject (readonly)

Returns the value of attribute order_ids.



8
9
10
# File 'app/models/work_completion/labware_completion.rb', line 8

def order_ids
  @order_ids
end

#submission_idsObject (readonly)

Returns the value of attribute submission_ids.



8
9
10
# File 'app/models/work_completion/labware_completion.rb', line 8

def submission_ids
  @submission_ids
end

#target_labwareObject (readonly)

Returns the value of attribute target_labware.



8
9
10
# File 'app/models/work_completion/labware_completion.rb', line 8

def target_labware
  @target_labware
end

#work_completionObject (readonly)

Returns the value of attribute work_completion.



8
9
10
# File 'app/models/work_completion/labware_completion.rb', line 8

def work_completion
  @work_completion
end

Instance Method Details

#connect_requestsObject

Must be implemented by any subclass. Finds the relevant target receptacle(s) and the requests coming into them. Calls pass_and_link_up_requests for each of them. Implemented differently for Plates and Tubes.

Raises:

  • (NotImplementedError)


26
27
28
# File 'app/models/work_completion/labware_completion.rb', line 26

def connect_requests
  raise NotImplementedError, 'abstract method'
end

#fire_eventsObject



56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/work_completion/labware_completion.rb', line 56

def fire_events
  order_ids.each do |order_id|
    BroadcastEvent::LibraryComplete.create!(
      seed: work_completion,
      user: work_completion.user,
      properties: {
        order_id:
      }
    )
  end
end

Updates the source receptacle (asset) of the downstream (normally sequencing) requests. Passes the requests coming into this labware’s receptacles (library requests). Collects order_ids, as these are needed to fire events.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/work_completion/labware_completion.rb', line 34

def pass_and_link_up_requests(target_receptacle, upstream_request)
  @order_ids << upstream_request.order_id

  # We need to find the downstream requests BEFORE connecting the upstream_request
  # This is because submission.next_requests tries to take a shortcut through
  # the target_asset if it is defined.
  upstream_request.next_requests.each { |ds| ds.update!(asset: target_receptacle) }

  # In some cases, such as the Illumina-C pipelines, requests might be
  # connected upfront. We don't want to touch these.
  upstream_request.target_asset ||= target_receptacle

  # We don't try and pass failed requests.
  # I'm not 100% convinced this decision belongs here, and instead
  # we may want to let the client specify wells to pass, and perform
  # validation to ensure this is correct. However this increases
  # the complexity of both the code and the interface, with only
  # marginal system simplification.
  upstream_request.pass if upstream_request.may_pass?
  upstream_request.save!
end

#processObject



17
18
19
20
# File 'app/models/work_completion/labware_completion.rb', line 17

def process
  connect_requests
  fire_events
end