Class: CloudFlow

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ CloudFlow

Returns a new instance of CloudFlow.

Parameters:

  • name (String)

    defines namespace. then it sees SQS Queue: ‘cloudflow_#name’



5
6
7
8
9
# File 'lib/cloud_flow.rb', line 5

def initialize(name)
  @namespace = name
  sqs = AWS::SQS.new
  @queue = sqs.queues.named("cloudflow_#{@namespace}")
end

Instance Method Details

#on(name, &block) ⇒ Object

regist func correspond to given func name. please avoid ‘on’, ‘poll’ since they are used already by CloudFlow. flow.on(:somefunc, &blk) generates flow#somefunc which is used to call the work.

Parameters:

  • name (String)

    the work’s name.

  • block (Block)

    the work.



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

def on(name, &block)
  define_sending_method(name)
  define_receiving_method(name, &block)
end

#startObject

starts its work.



22
23
24
25
26
# File 'lib/cloud_flow.rb', line 22

def start
  @queue.poll do |msg|
    perform_message(msg)
  end
end