jmettraux (owner)

Forks

Revisions

gist: 35894 Download_button fork
public
Public Clone URL: git://gist.github.com/35894.git
Embed All Files: show embed
qs.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
53
54
55
56
57
58
59
60
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
require 'rubygems'
require 'openwfe/engine/file_persisted_engine' # sudo gem install ruote
 
engine = OpenWFE::FilePersistedEngine.new(
  :definition_in_launchitem_allowed => true)
 
#
# the process definition
 
class MyTodoProcess < OpenWFE::ProcessDefinition
  cursor do
    perform_task
    continue :unless => "${f:over}"
  end
end
 
#
# the participant
 
engine.register_participant :perform_task do |workitem|
  puts
  puts " done :"
  workitem.done.each do |task, time|
    puts "- #{task} - #{time}"
  end
  puts
  puts " todo :"
  workitem.todo.each_with_index do |task, i|
    puts "#{i}) #{task}"
  end
  puts
  print "task # (n for new, x for exit) ==> "
  i = gets.strip
  if i == 'n'
    print "new task : "
    workitem.todo << gets.strip
  elsif i == 'x'
    exit 0
  else
    t = workitem.todo.delete_at(i.to_i)
    workitem.done << [ t, Time.now.to_s ] if t
  end
  workitem.over = (workitem.todo.size == 0)
end
 
#
# process already running ?
 
ps = engine.process_statuses.values[0]
 
fei = if ps
 
  #
  # yes, there is already a running process, resume it...
 
  engine.replay_at_error(ps.errors.values[0])
 
  puts "using already launched process..."
 
  sleep 0.350
 
  ps.wfid
 
else
 
  #
  # no process running, launch a new one...
 
  li = OpenWFE::LaunchItem.new(MyTodoProcess)
  li.goal = "meeting preparation"
  li.todo = [
    "reserve room",
    "reserve beamer",
    "send invitations",
    "order sandwiches"
  ]
  li.done = []
 
  engine.launch(li)
 
end
 
#
# don't exit before the process is over
 
engine.wait_for(fei)