forked from floraison/flor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickstart.rb
53 lines (42 loc) · 1.31 KB
/
quickstart.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'flor/unit'
#ENV['FLOR_DEBUG'] = 'dbg,sto,stdout' # full sql + flor debug output
#ENV['FLOR_DEBUG'] = 'dbg,stdout' # flor debug output
# uncomment to see the flor activity
sto_uri = 'sqlite://flor_qs.db'
sto_uri = 'jdbc:sqlite://flor_qs.db' if RUBY_PLATFORM.match(/java/)
flor = Flor::Unit.new(loader: Flor::HashLoader, sto_uri: sto_uri)
# instantiate flor unit
flor.storage.delete_tables
flor.storage.migrate
# blank slate database
class DemoTasker < Flor::BasicTasker
def task(message)
(attd['times'] || 1).times do
message['payload']['log'] << "#{tasker}: #{task_name}"
end
reply
end
end
flor.add_tasker(:alice, DemoTasker)
flor.add_tasker(:bob, DemoTasker)
# a simple logging tasker implementation bound under
# two different tasker names
flor.start
# start the flor unit, so that it can process executions
exid = flor.launch(
%q{
sequence
alice 'hello' times: 2
bob 'world'
},
payload: { log: [ "started at #{Time.now}" ] })
# launch a new execution, one that chains alice and bob work
#r = flor.wait(exid, 'terminated')
r = flor.wait(exid)
# wait for the execution to terminate or to fail
p r['point']
# "terminated" hopefully
p r['payload']['log']
# [ "started at 2019-03-31 10:20:18 +0900",
# "alice: hello", "alice: hello",
# "bob: world" ]