Module: Jobs::States

Included in:
Job
Defined in:
app/models/jobs/states.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


3
4
5
6
7
8
# File 'app/models/jobs/states.rb', line 3

def self.included(base)
  base.class_eval do
    before_create :set_initial_state
    after_create :create_initial_state_change
  end
end

Instance Method Details

#create_state_change(message = nil) ⇒ Object


29
30
31
# File 'app/models/jobs/states.rb', line 29

def create_state_change(message = nil)
  state_changes.create!(state: state, message: message)
end

#enter(new_state, params = {}, _headers = {}) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/jobs/states.rb', line 14

def enter(new_state, params = {}, _headers = {})
  with_lock(true) do
    if state != new_state
      self.state = new_state

      create_state_change(params['message'])

      send("enter_#{new_state}", params)
      save
    end
  end

  self
end

#initial_stateObject


10
11
12
# File 'app/models/jobs/states.rb', line 10

def initial_state
  Job::Scheduled
end