Class: Task Deprecated

Inherits:
ApplicationRecord show all
Defined in:
app/models/task.rb

Overview

Deprecated.

Task form a large number of legacy pipelines in Sequencescape, however most

Note:

A large number of tasks delegate a large portion of their behaviour back to the

A Task forms part of a Workflow which in turn describes the steps that form a Pipeline. Most tasks are a subclass of Task

more recent pipelines exist outside of Sequencescape itself.

Tasks have three key methods #render_task: Which handles rendering the form displayed to the user #do_task: Which takes the parameters from the form, and performs the task in question #partial: Inicates which partial to render when displaying the form.

WorkflowsController. This behaviour is mostly defined in modules under Task.

Defined Under Namespace

Classes: RenderElement

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Class Method Details

.get_subclass_attribute_options(name) ⇒ Object


77
78
79
80
# File 'app/models/task.rb', line 77

def self.get_subclass_attribute_options(name)
  init_class
  @subclass_attributes[name]
end

.get_subclass_attributesObject


86
87
88
89
# File 'app/models/task.rb', line 86

def self.get_subclass_attributes
  init_class
  @subclass_attributes_ordered_names
end

.init_classObject


69
70
71
72
73
74
75
# File 'app/models/task.rb', line 69

def self.init_class
  return if @init_done

  @init_done = true
  @subclass_attributes = {}
  @subclass_attributes_ordered_names = []
end

.set_subclass_attribute(name, options = {}) ⇒ Object

Raises:

  • (ArgumentError)

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/task.rb', line 95

def self.set_subclass_attribute(name, options = {})
  init_class
  raise ArgumentError, "subclass attribute #{name} already in use" if @subclass_attributes.include? name

  @subclass_attributes[name] = options
  @subclass_attributes_ordered_names << name

  kind = options[:kind]
  cast = options[:cast]
  default_value = options[:default]

  define_method(name) do
    value = get_subclass_attribute_value name, default_value # we love closure :)
    value and case cast
              when :int
                value.to_i
              else
                value
              end
  end

  define_method("#{name}=") do |value|
    set_subclass_attribute_value(name, value, kind)
  end
end

Instance Method Details

#create_render_element(request) ⇒ Object


146
147
148
# File 'app/models/task.rb', line 146

def create_render_element(request)
  request && RenderElement.new(request)
end

#do_task(_controller, _params) ⇒ Object

Raises:

  • (NotImplementedError)

150
151
152
# File 'app/models/task.rb', line 150

def do_task(_controller, _params)
  raise NotImplementedError, "Please Implement a do_task for #{self.class.name}"
end

#find_batch(batch_id) ⇒ Object


158
159
160
# File 'app/models/task.rb', line 158

def find_batch(batch_id)
  Batch.includes(:requests, :pipeline, :lab_events).find(batch_id)
end

#find_batch_requests(batch_id) ⇒ Object


162
163
164
# File 'app/models/task.rb', line 162

def find_batch_requests(batch_id)
  find_batch(batch_id).ordered_requests
end

#get_descriptor_value(name, default = nil) ⇒ Object

TODO: move into SetDescriptorsTask


24
25
26
27
28
29
30
31
32
# File 'app/models/task.rb', line 24

def get_descriptor_value(name, default = nil)
  name_s = name.to_s
  descriptors.each do |desc|
    if desc.name.eql?(name_s)
      return desc.value
    end
  end
  default
end

#get_subclass_attribute_options(name) ⇒ Object


82
83
84
# File 'app/models/task.rb', line 82

def get_subclass_attribute_options(name)
  self.class.get_subclass_attribute_options(name)
end

#get_subclass_attribute_value(name, default = nil) ⇒ Object


48
49
50
51
52
53
54
55
56
# File 'app/models/task.rb', line 48

def get_subclass_attribute_value(name, default = nil)
  name_s = name.to_s
  subclass_attributes.each do |desc|
    if desc.name.eql?(name_s)
      return desc.value
    end
  end
  default
end

#get_subclass_attributesObject


91
92
93
# File 'app/models/task.rb', line 91

def get_subclass_attributes
  self.class.get_subclass_attributes
end

#included_for_do_taskObject


134
135
136
# File 'app/models/task.rb', line 134

def included_for_do_task
  [:requests, :pipeline, :lab_events]
end

#included_for_render_taskObject


138
139
140
# File 'app/models/task.rb', line 138

def included_for_render_task
  [:requests, :pipeline, :lab_events]
end

#partialObject


131
132
# File 'app/models/task.rb', line 131

def partial
end

#render_task(controller, params) ⇒ Object


142
143
144
# File 'app/models/task.rb', line 142

def render_task(controller, params)
  controller.render_task(self, params)
end

#set_descriptor_value(name, value, _kind = nil) ⇒ Object


34
35
36
37
38
39
40
41
42
43
# File 'app/models/task.rb', line 34

def set_descriptor_value(name, value, _kind = nil)
  name_s = name.to_s
  descriptors.each do |desc|
    if desc.name.eql?(name_s)
      desc.value = value
      return
    end
  end
  descriptors << Descriptor.new(name: name_s, value: value)
end

#set_subclass_attribute_value(name, value, _kind = nil) ⇒ Object


58
59
60
61
62
63
64
65
66
67
# File 'app/models/task.rb', line 58

def set_subclass_attribute_value(name, value, _kind = nil)
  name_s = name.to_s
  subclass_attributes.each do |desc|
    if desc.name.eql?(name_s)
      desc.value = value
      return
    end
  end
  subclass_attributes << SubclassAttribute.new(name: name_s, value: value)
end

#sub_events_for(_event) ⇒ Object


154
155
156
# File 'app/models/task.rb', line 154

def sub_events_for(_event)
  []
end