Class: Saga

Inherits:
Object
  • Object
show all
Defined in:
lib/cirrocumulus/saga.rb

Overview

Saga. Implements long-running workflows

Constant Summary collapse

STATE_ERROR =
-1
STATE_START =
0
STATE_FINISHED =
255
@@saga_names =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, ontology) ⇒ Saga

Returns a new instance of Saga.



20
21
22
23
24
25
26
# File 'lib/cirrocumulus/saga.rb', line 20

def initialize(id, ontology)
  @id = id
  @ontology = ontology
  @state = STATE_START
  @started_at = Time.now
  @timeout_at = nil
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'lib/cirrocumulus/saga.rb', line 18

def id
  @id
end

Class Method Details

.saga(saga_name = nil) ⇒ Object



8
9
10
11
# File 'lib/cirrocumulus/saga.rb', line 8

def saga(saga_name = nil)
  return @@saga_names[name] if saga_name.nil?
  @@saga_names[name] = saga_name
end

Instance Method Details

#dump_parametersObject



41
42
43
# File 'lib/cirrocumulus/saga.rb', line 41

def dump_parameters
  ""
end

#handle_reply(sender, contents, options = {}) ⇒ Object



39
# File 'lib/cirrocumulus/saga.rb', line 39

def handle_reply(sender, contents, options = {}); end

#is_finished?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cirrocumulus/saga.rb', line 28

def is_finished?
  @state == STATE_ERROR || @state == STATE_FINISHED
end

#tickObject



32
33
34
35
36
37
# File 'lib/cirrocumulus/saga.rb', line 32

def tick
  return if @timeout_at.nil? || @timeout_at > Time.now

  @timeout_at = nil
  handle_reply(nil, nil, nil)
end

#to_sObject



45
46
47
# File 'lib/cirrocumulus/saga.rb', line 45

def to_s
  "%s type=%s, started at %s, state=%d, params: %s" % [@id, @@saga_names[self.class.name], @started_at, @state, dump_parameters]
end