Class: Seam::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/seam/worker.rb

Direct Known Subclasses

WaitWorker

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#operation_argsObject

Returns the value of attribute operation_args.



56
57
58
# File 'lib/seam/worker.rb', line 56

def operation_args
  @operation_args
end

Class Method Details

.allObject



29
30
31
# File 'lib/seam/worker.rb', line 29

def self.all
  (@handlers || []).map { |x| x.new }
end

.handler_for(step) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/seam/worker.rb', line 21

def self.handler_for step
  @handlers.each do |handler|
    instance = handler.new
    return instance if instance.step == step
  end
  nil
end

.inherited(handler) ⇒ Object



16
17
18
19
# File 'lib/seam/worker.rb', line 16

def self.inherited handler
  @handlers ||= []
  @handlers << handler
end

Instance Method Details

#current_stepObject



104
105
106
# File 'lib/seam/worker.rb', line 104

def current_step
  effort.flow["steps"][effort.completed_steps.count]
end

#effortObject



91
92
93
# File 'lib/seam/worker.rb', line 91

def effort
  @current_effort
end

#ejectObject



37
38
39
# File 'lib/seam/worker.rb', line 37

def eject
  @operation_to_execute = :eject
end

#execute(effort) ⇒ Object



9
10
11
12
13
14
# File 'lib/seam/worker.rb', line 9

def execute effort
  set_current_effort effort
  before_process
  process
  after_process
end

#execute_allObject



33
34
35
# File 'lib/seam/worker.rb', line 33

def execute_all
  efforts_to_execute.each { |e| execute e }
end

#handles(step) ⇒ Object



5
6
7
# File 'lib/seam/worker.rb', line 5

def handles step
  @step = step
end

#historyObject



95
96
97
# File 'lib/seam/worker.rb', line 95

def history
  @current_run
end

#move_to_next_step(options = {}) ⇒ Object



41
42
43
44
# File 'lib/seam/worker.rb', line 41

def move_to_next_step(options = {})
  @operation_to_execute = :move_to_next_step
  operation_args[:next_execute_at] = (options[:on] || Time.now)
end

#operationsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/seam/worker.rb', line 61

def operations
  {
    try_again_in:      -> do
                            seconds = operation_args[:seconds]
                            try_again_on = Time.now + seconds

                            history[:try_again_on] = try_again_on

                            effort.next_execute_at = try_again_on
                          end,
    try_again_on:      -> do
                            history[:try_again_on] = operation_args[:time]
                            effort.next_execute_at = operation_args[:time]
                          end,
    move_to_next_step: -> do
                            effort.next_execute_at = operation_args[:next_execute_at] if operation_args[:next_execute_at]

                            effort.completed_steps << effort.next_step

                            steps = effort.flow['steps'].map { |x| x['name'] }
                            next_step = steps[effort.completed_steps.count]

                            effort.next_step = next_step
                            mark_effort_as_complete if next_step.nil?

                          end,
    eject:             -> { mark_effort_as_complete }
  }
end

#stepObject



99
100
101
102
# File 'lib/seam/worker.rb', line 99

def step
  s = @step || self.class.name.underscore.gsub('_worker', '').split('/')[-1]
  s.to_s
end

#try_again_in(seconds) ⇒ Object



46
47
48
49
# File 'lib/seam/worker.rb', line 46

def try_again_in seconds
  @operation_to_execute    = :try_again_in
  operation_args[:seconds] = seconds
end

#try_again_on(time) ⇒ Object



51
52
53
54
# File 'lib/seam/worker.rb', line 51

def try_again_on time
  @operation_to_execute = :try_again_on
  operation_args[:time] = time
end