bunnicula 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/Rakefile +2 -2
  2. data/bunnicula.gemspec +180 -3
  3. data/lib/bunnicula/version.rb +1 -1
  4. data/vendor/daemon_kit/daemon-kit/Configuration.txt +110 -0
  5. data/vendor/daemon_kit/daemon-kit/Deployment.txt +113 -0
  6. data/vendor/daemon_kit/daemon-kit/History.txt +113 -0
  7. data/vendor/daemon_kit/daemon-kit/Logging.txt +96 -0
  8. data/vendor/daemon_kit/daemon-kit/Manifest.txt +172 -0
  9. data/vendor/daemon_kit/daemon-kit/PostInstall.txt +6 -0
  10. data/vendor/daemon_kit/daemon-kit/README.rdoc +126 -0
  11. data/vendor/daemon_kit/daemon-kit/Rakefile +29 -0
  12. data/vendor/daemon_kit/daemon-kit/RuoteParticipants.txt +113 -0
  13. data/vendor/daemon_kit/daemon-kit/TODO.txt +28 -0
  14. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/USAGE +7 -0
  15. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/daemon_kit_generator.rb +178 -0
  16. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/README +48 -0
  17. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/Rakefile +6 -0
  18. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
  19. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
  20. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/boot.rb +59 -0
  21. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environment.rb +23 -0
  22. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environments/development.rb +2 -0
  23. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environments/production.rb +5 -0
  24. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/environments/test.rb +2 -0
  25. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/post-daemonize/readme +5 -0
  26. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/config/pre-daemonize/readme +12 -0
  27. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/lib/daemon.rb +2 -0
  28. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
  29. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/script/console +3 -0
  30. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/script/destroy +14 -0
  31. data/vendor/daemon_kit/daemon-kit/app_generators/daemon_kit/templates/script/generate +14 -0
  32. data/vendor/daemon_kit/daemon-kit/bin/daemon-kit +18 -0
  33. data/vendor/daemon_kit/daemon-kit/config/website.yml +2 -0
  34. data/vendor/daemon_kit/daemon-kit/daemon-kit.gemspec +264 -0
  35. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/USAGE +5 -0
  36. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/amqp_generator.rb +65 -0
  37. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/templates/config/amqp.yml +28 -0
  38. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/templates/config/initializers/amqp.rb +7 -0
  39. data/vendor/daemon_kit/daemon-kit/daemon_generators/amqp/templates/libexec/daemon.rb +37 -0
  40. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/USAGE +5 -0
  41. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/cron_generator.rb +64 -0
  42. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/templates/config/initializers/cron.rb +11 -0
  43. data/vendor/daemon_kit/daemon-kit/daemon_generators/cron/templates/libexec/daemon.rb +43 -0
  44. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/USAGE +11 -0
  45. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/cucumber_generator.rb +38 -0
  46. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/cucumber +8 -0
  47. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/cucumber.rake +13 -0
  48. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/cucumber_environment.rb +2 -0
  49. data/vendor/daemon_kit/daemon-kit/daemon_generators/cucumber/templates/env.rb +7 -0
  50. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
  51. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
  52. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
  53. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy.rb +53 -0
  54. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
  55. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
  56. data/vendor/daemon_kit/daemon-kit/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
  57. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/USAGE +5 -0
  58. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/jabber_generator.rb +65 -0
  59. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/templates/config/initializers/jabber.rb +7 -0
  60. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/templates/config/jabber.yml +26 -0
  61. data/vendor/daemon_kit/daemon-kit/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
  62. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/USAGE +5 -0
  63. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/nanite_agent_generator.rb +68 -0
  64. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb +6 -0
  65. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/config/nanite.yml +35 -0
  66. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/lib/actors/sample.rb +11 -0
  67. data/vendor/daemon_kit/daemon-kit/daemon_generators/nanite_agent/templates/libexec/daemon.rb +31 -0
  68. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/USAGE +5 -0
  69. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/rspec_generator.rb +55 -0
  70. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/spec.rb +11 -0
  71. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/spec/spec.opts +1 -0
  72. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/spec/spec_helper.rb +23 -0
  73. data/vendor/daemon_kit/daemon-kit/daemon_generators/rspec/templates/tasks/rspec.rake +19 -0
  74. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/USAGE +5 -0
  75. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/ruote_generator.rb +67 -0
  76. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/config/amqp.yml +30 -0
  77. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/config/initializers/ruote.rb +13 -0
  78. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/config/ruote.yml +23 -0
  79. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/lib/daemon.rb +4 -0
  80. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/lib/sample.rb +26 -0
  81. data/vendor/daemon_kit/daemon-kit/daemon_generators/ruote/templates/libexec/daemon.rb +33 -0
  82. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/USAGE +5 -0
  83. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/templates/tasks/test_unit.rake +7 -0
  84. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/templates/test/test.rb +9 -0
  85. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/templates/test/test_helper.rb +6 -0
  86. data/vendor/daemon_kit/daemon-kit/daemon_generators/test_unit/test_unit_generator.rb +51 -0
  87. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit.rb +62 -0
  88. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/abstract_logger.rb +241 -0
  89. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/amqp.rb +38 -0
  90. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/application.rb +188 -0
  91. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/arguments.rb +170 -0
  92. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/commands/console.rb +38 -0
  93. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/config.rb +108 -0
  94. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/console_daemon.rb +2 -0
  95. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/core_ext.rb +1 -0
  96. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/core_ext/configurable.rb +96 -0
  97. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/core_ext/string.rb +22 -0
  98. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/cron.rb +48 -0
  99. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/cucumber/world.rb +38 -0
  100. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/deployment/capistrano.rb +482 -0
  101. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/em.rb +43 -0
  102. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/error_handlers/base.rb +32 -0
  103. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/error_handlers/hoptoad.rb +61 -0
  104. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/error_handlers/mail.rb +85 -0
  105. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/exceptions.rb +15 -0
  106. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/initializer.rb +453 -0
  107. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/jabber.rb +170 -0
  108. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/nanite.rb +7 -0
  109. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/nanite/agent.rb +77 -0
  110. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/pid_file.rb +61 -0
  111. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/ruote_participants.rb +119 -0
  112. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
  113. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/ruote_workitem.rb +177 -0
  114. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/safety.rb +85 -0
  115. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks.rb +2 -0
  116. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/environment.rake +10 -0
  117. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/framework.rake +120 -0
  118. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/god.rake +62 -0
  119. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/log.rake +8 -0
  120. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/tasks/monit.rake +29 -0
  121. data/vendor/daemon_kit/daemon-kit/lib/daemon_kit/xmpp.rb +31 -0
  122. data/vendor/daemon_kit/daemon-kit/script/console +10 -0
  123. data/vendor/daemon_kit/daemon-kit/script/destroy +14 -0
  124. data/vendor/daemon_kit/daemon-kit/script/generate +14 -0
  125. data/vendor/daemon_kit/daemon-kit/script/txt2html +71 -0
  126. data/vendor/daemon_kit/daemon-kit/spec/abstract_logger_spec.rb +126 -0
  127. data/vendor/daemon_kit/daemon-kit/spec/argument_spec.rb +70 -0
  128. data/vendor/daemon_kit/daemon-kit/spec/config_spec.rb +79 -0
  129. data/vendor/daemon_kit/daemon-kit/spec/configurable_spec.rb +56 -0
  130. data/vendor/daemon_kit/daemon-kit/spec/daemon_kit_spec.rb +7 -0
  131. data/vendor/daemon_kit/daemon-kit/spec/error_handlers_spec.rb +23 -0
  132. data/vendor/daemon_kit/daemon-kit/spec/fixtures/env.yml +15 -0
  133. data/vendor/daemon_kit/daemon-kit/spec/fixtures/noenv.yml +4 -0
  134. data/vendor/daemon_kit/daemon-kit/spec/initializer_spec.rb +26 -0
  135. data/vendor/daemon_kit/daemon-kit/spec/spec.opts +1 -0
  136. data/vendor/daemon_kit/daemon-kit/spec/spec_helper.rb +27 -0
  137. data/vendor/daemon_kit/daemon-kit/tasks/cucumber.rake +13 -0
  138. data/vendor/daemon_kit/daemon-kit/tasks/rspec.rake +21 -0
  139. data/vendor/daemon_kit/daemon-kit/tasks/tests.rake +6 -0
  140. data/vendor/daemon_kit/daemon-kit/templates/god/god.erb +69 -0
  141. data/vendor/daemon_kit/daemon-kit/templates/monit/monit.erb +14 -0
  142. data/vendor/daemon_kit/daemon-kit/test/test_amqp_generator.rb +48 -0
  143. data/vendor/daemon_kit/daemon-kit/test/test_cron_generator.rb +45 -0
  144. data/vendor/daemon_kit/daemon-kit/test/test_daemon-kit_generator.rb +84 -0
  145. data/vendor/daemon_kit/daemon-kit/test/test_daemon_kit_config.rb +28 -0
  146. data/vendor/daemon_kit/daemon-kit/test/test_deploy_capistrano_generator.rb +48 -0
  147. data/vendor/daemon_kit/daemon-kit/test/test_generator_helper.rb +29 -0
  148. data/vendor/daemon_kit/daemon-kit/test/test_helper.rb +7 -0
  149. data/vendor/daemon_kit/daemon-kit/test/test_jabber_generator.rb +49 -0
  150. data/vendor/daemon_kit/daemon-kit/test/test_nanite_agent_generator.rb +49 -0
  151. data/vendor/daemon_kit/daemon-kit/test/test_ruote_generator.rb +51 -0
  152. data/vendor/daemon_kit/daemon-kit/test/test_test_unit_generator.rb +46 -0
  153. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail.rb +5 -0
  154. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/address.rb +426 -0
  155. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
  156. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
  157. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
  158. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/config.rb +67 -0
  159. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
  160. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
  161. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/header.rb +960 -0
  162. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/index.rb +9 -0
  163. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
  164. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
  165. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
  166. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
  167. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/main.rb +6 -0
  168. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
  169. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/net.rb +248 -0
  170. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
  171. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
  172. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/port.rb +379 -0
  173. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
  174. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
  175. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
  176. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
  177. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
  178. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
  179. data/vendor/daemon_kit/daemon-kit/vendor/tmail-1.2.3/tmail/version.rb +39 -0
  180. data/vendor/daemon_kit/daemon-kit/vendor/tmail.rb +13 -0
  181. metadata +181 -4
@@ -0,0 +1,177 @@
1
+ module DaemonKit
2
+
3
+ # Dual purpose class that is a) responsible for parsing incoming workitems and
4
+ # delegating to the correct RuotePseudoParticipant, and b) wrapping the
5
+ # workitem hash into something a bit more digestable.
6
+ class RuoteWorkitem
7
+
8
+ class << self
9
+
10
+ # = Process incoming commands via an AMQP queue
11
+ #
12
+ # Expects a JSON workitem from ruote that has these fields set in
13
+ # attributes key:
14
+ #
15
+ # {
16
+ # 'reply_queue' => 'queue to send replies to',
17
+ # 'params' => {
18
+ # 'command' => '/actor/method'
19
+ # }
20
+ # }
21
+ #
22
+ # == Notes on the command key:
23
+ #
24
+ # It looks like a resource, and will be treated as such. Is should
25
+ # be in the format of +/class/method+, and it will be passed the
26
+ # complete workitem as a hash.
27
+ #
28
+ # == Notes on replies
29
+ #
30
+ # Replies are sent back to the queue specified in the +reply_queue+ key.
31
+ #
32
+ # == Notes on errors
33
+ #
34
+ # Where daemon-kit detects errors in attempting to parse and delegate the
35
+ # workitems, it will reply to the engine and set the following field with
36
+ # the error information:
37
+ #
38
+ # daemon_kit.error
39
+ def process( transport, workitem )
40
+ # keep it singleton
41
+ @instance ||= new
42
+
43
+ work = parse( workitem )
44
+
45
+ # Invalid JSON... mmm
46
+ return if work.nil?
47
+
48
+ DaemonKit.logger.warn "Processing workitem that has timed out!" if work.timed_out?
49
+
50
+ target, method = parse_command( work )
51
+
52
+ if target.nil? || method.nil?
53
+ msg = "Missing target/method in command parameter, or command parameter missing"
54
+ DaemonKit.logger.error( msg )
55
+ work["daemon_kit"] = { "error" => msg }
56
+
57
+ elsif target.public_methods.include?( method )
58
+ target.perform( method, work )
59
+
60
+ else
61
+ msg = "Workitem cannot be processes: #{method} not exposed by #{target.inspect}"
62
+ DaemonKit.logger.error( msg )
63
+ work["daemon_kit"] = { "error" => msg }
64
+ end
65
+
66
+ reply_to_engine( transport, work )
67
+ end
68
+
69
+ # Extract the class and method name from the workitem, then pick the matching
70
+ # class from the registered list of participants
71
+ def parse_command( work )
72
+ return nil if work['params']['command'].nil?
73
+
74
+ _, klass, method = work['params']['command'].split('/')
75
+
76
+ instance = RuoteParticipants.instance.participants[ klass ]
77
+
78
+ if instance.nil?
79
+ msg = "No instance registered for #{klass}"
80
+ DaemonKit.logger.error( msg )
81
+ raise DaemonKit::MissingParticipant, msg
82
+ end
83
+
84
+ return instance, method
85
+ end
86
+
87
+ def reply_to_engine( transport, response )
88
+ send( "reply_via_#{transport}", response )
89
+ end
90
+
91
+ def reply_via_amqp( response )
92
+ DaemonKit.logger.debug("Replying to engine via AMQP with #{response.inspect}")
93
+
94
+ ::MQ.queue( response['reply_queue'] ).publish( response.to_json )
95
+
96
+ response
97
+ end
98
+
99
+ def parse( workitem )
100
+ begin
101
+ return new( JSON.parse( workitem ) )
102
+ rescue JSON::ParserError => e
103
+ DaemonKit.logger.error "No valid JSON payload found in #{workitem}"
104
+ return nil
105
+ end
106
+ end
107
+ end
108
+
109
+ def initialize( workitem = {} )
110
+ @workitem = workitem
111
+ end
112
+
113
+ def fei
114
+ @workitem['flow_expression_id']
115
+ end
116
+
117
+ def short_fei
118
+ @short_fei ||=
119
+ '(' + [
120
+ 'fei', self.fei['owfe_version'], self.fei['engine_id'],
121
+ self.fei['workflow_definition_url'], self.fei['workflow_definition_name'],
122
+ self.fei['workflow_definition_revision'], self.fei['workflow_instance_id'],
123
+ self.fei['expression_name'], self.fei['expression_id']
124
+ ].join(' ') + ')'
125
+ end
126
+
127
+ def dispatch_time
128
+ @dispath_time ||= Time.parse( @workitem['dispatch_time'] )
129
+ end
130
+
131
+ def last_modified
132
+ @last_modified ||= Time.parse( @workitem['last_modified'] )
133
+ end
134
+
135
+ def participant_name
136
+ @workitem['participant_name']
137
+ end
138
+
139
+ def attributes
140
+ @workitem['attributes']
141
+ end
142
+
143
+ def []( key )
144
+ self.attributes[ key ]
145
+ end
146
+
147
+ def []=( key, value )
148
+ self.attributes[ key ] = value
149
+ end
150
+
151
+ def to_json
152
+ @workitem.to_json
153
+ end
154
+
155
+ # Look at the workitem payload and attempt to determine if this workitem
156
+ # has timed out or not. This method will only ever work if you used the
157
+ # +:timeout: parameter was set for the expression.
158
+ def timed_out?
159
+ key = fei['workflow_instance_id'] + '__' + fei['expression_id']
160
+
161
+ if self.attributes["__timeouts__"] && timeout = self.attributes["__timeouts__"][ key ]
162
+ return Time.at( timeout.last ) < Time.now
163
+ end
164
+
165
+ return false
166
+ end
167
+
168
+ def method_missing( method_name, *args )
169
+ if self.attributes.keys.include?( method_name.to_s )
170
+ return self.attributes[ method_name.to_s ]
171
+ end
172
+
173
+ super
174
+ end
175
+
176
+ end
177
+ end
@@ -0,0 +1,85 @@
1
+ module DaemonKit
2
+ # Provides a wrapper for running code inside a 'safety net' Any
3
+ # exceptions raised inside a safety net is handled and reported via
4
+ # loggers, email or Hoptoad.
5
+ #
6
+ # The safety net can be configured via DaemonKit.config.safety,
7
+ # which holds the only instance of the safety net.
8
+ class Safety
9
+
10
+ # Who get's notified.
11
+ @handler = nil
12
+ attr_accessor :handler
13
+
14
+ # Registered error handlers
15
+ @error_handlers = {}
16
+ attr_reader :error_handlers
17
+
18
+ class << self
19
+
20
+ # Singleton
21
+ @instance = nil
22
+
23
+ def instance
24
+ @instance ||= new
25
+ end
26
+ private :new
27
+
28
+ # Run the provided block inside a safety net.
29
+ def run(&block)
30
+ self.instance.run(&block)
31
+ end
32
+
33
+ def register_error_handler( klass )
34
+ name = klass.to_s.split('::').last.downcase
35
+
36
+ DaemonKit.logger.debug( "Registering error handler '#{name}' (#{klass})" ) if DaemonKit.logger
37
+
38
+ instance.instance_eval( <<-EOF, __FILE__, __LINE__ )
39
+ def #{name}
40
+ @#{name} ||= #{klass}.instance
41
+ end
42
+ EOF
43
+ end
44
+ end
45
+
46
+ # Run the provided block inside a safety net.
47
+ def run(&block)
48
+ begin
49
+ block.call
50
+ rescue => e
51
+ # Log
52
+ DaemonKit.logger.fatal "Safety net caught exception: #{e.message}"
53
+ DaemonKit.logger.fatal "Backtrace: #{e.backtrace.join("\n ")}"
54
+
55
+ get_handler.handle_exception( e ) if get_handler
56
+ end
57
+ end
58
+
59
+ def get_handler
60
+ if @handler && self.respond_to?( @handler )
61
+ h = send( @handler )
62
+ return h if h.class.ancestors.include?( DaemonKit::ErrorHandlers::Base )
63
+ end
64
+
65
+ return nil
66
+ end
67
+ end
68
+ end
69
+
70
+ class Object
71
+ class << self
72
+ def safely(&block)
73
+ DaemonKit::Safety.run(&block)
74
+ end
75
+ end
76
+
77
+ def safely(&block)
78
+ DaemonKit::Safety.run(&block)
79
+ end
80
+ end
81
+
82
+ # Load our error handlers
83
+ require 'daemon_kit/error_handlers/base'
84
+ require 'daemon_kit/error_handlers/mail'
85
+ require 'daemon_kit/error_handlers/hoptoad'
@@ -0,0 +1,2 @@
1
+ # Load all the take tasks in the gem
2
+ Dir[File.join(File.dirname(__FILE__), '**/*.rake')].each { |rake| load rake }
@@ -0,0 +1,10 @@
1
+ task :environment do
2
+ $daemon_kit_rake_task = true
3
+
4
+ require 'config/environment'
5
+ end
6
+
7
+ task "Execute system commands in other tasks with sudo"
8
+ task :sudo do
9
+ $RAKE_USE_SUDO = true
10
+ end
@@ -0,0 +1,120 @@
1
+ namespace :daemon_kit do
2
+ namespace :freeze do
3
+ desc "Lock this application to the current gem (by unpacking it into vendor/daemon_kit)"
4
+ task :gems do
5
+ deps = %w()
6
+ require 'rubygems'
7
+ require 'rubygems/gem_runner'
8
+
9
+ kit = (version = ENV['VERSION']) ?
10
+ Gem.cache.find_name('daemon-kit', "= #{version}").first :
11
+ Gem.cache.find_name('daemon-kit').sort_by { |g| g.version }.last
12
+
13
+ version ||= kit.version
14
+
15
+ unless kit
16
+ puts "No daemon_kit gem #{version} is installed. Do 'gem list daemon_kit' to see what you have available."
17
+ exit
18
+ end
19
+
20
+ puts "Freezing the gem for DaemonKit #{kit.version}"
21
+ rm_rf "vendor/daemon_kit"
22
+ mkdir_p "vendor/daemon_kit"
23
+
24
+ begin
25
+ chdir("vendor/daemon_kit") do
26
+ kit.dependencies.select { |g| deps.include? g.name }.each do |g|
27
+ Gem::GemRunner.new.run(["unpack", g.name, "--version", g.version_requirements.to_s])
28
+ mv(Dir.glob("#{g.name}*").first, g.name)
29
+ end
30
+
31
+ Gem::GemRunner.new.run(["unpack", "daemon-kit", "--version", "=#{version}"])
32
+ FileUtils.mv(Dir.glob("daemon-kit*").first, "daemon-kit")
33
+ end
34
+ rescue Exception
35
+ rm_rf "vendor/daemon_kit"
36
+ raise
37
+ end
38
+ end
39
+
40
+ desc 'Lock to latest edge daemon_kit'
41
+ task :edge do
42
+ require 'open-uri'
43
+ #version = ENV["RELEASE"] || "edge"
44
+ commits = "http://github.com/api/v1/yaml/kennethkalmer/daemon-kit/commits/master"
45
+ url = "http://github.com/kennethkalmer/daemon-kit/zipball/master"
46
+
47
+ rm_rf "vendor/daemon_kit"
48
+ mkdir_p "vendor/daemon_kit"
49
+
50
+ chdir 'vendor/daemon_kit' do
51
+ latest_revision = YAML.load(open(commits))["commits"].first["id"]
52
+
53
+ puts "Downloading DaemonKit from #{url}"
54
+ File.open('daemon-kit.zip', 'wb') do |dst|
55
+ open url do |src|
56
+ while chunk = src.read(4096)
57
+ dst << chunk
58
+ end
59
+ end
60
+ end
61
+
62
+ puts 'Unpacking DaemonKit'
63
+ rm_rf 'daemon-kit'
64
+ `unzip daemon-kit.zip`
65
+ FileUtils.mv(Dir.glob("kennethkalmer-daemon-kit*").first, "daemon-kit")
66
+ %w(daemon-kit.zip).each do |goner|
67
+ rm_f goner
68
+ end
69
+
70
+ touch "REVISION_#{latest_revision}"
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ desc "Upgrade your local files for a daemon after upgrading daemon-kit"
77
+ task :upgrade => 'environment' do
78
+ # Run these
79
+ %w{ initializers rakefile scripts }.each do |t|
80
+ Rake::Task["daemon_kit:upgrade:#{t}"].invoke
81
+ end
82
+
83
+ puts
84
+ puts "#{DaemonKit.configuration.daemon_name} has been upgraded."
85
+ end
86
+
87
+ namespace :upgrade do
88
+ # Upgrade the initializers
89
+ task :initializers do
90
+ copy_framework_template( 'config', 'boot.rb' )
91
+
92
+ if File.directory?( File.join(DaemonKit.root, 'config', 'initializers') )
93
+ mv File.join(DaemonKit.root, 'config', 'initializers'), File.join(DAEMON_ROOT, 'config', 'pre-daemonize')
94
+ copy_framework_template( 'config', 'pre-daemonize', 'readme' )
95
+ end
96
+
97
+ unless File.directory?( File.join(DAEMON_ROOT, 'config', 'post-daemonize') )
98
+ mkdir_p File.join(DAEMON_ROOT, 'config', 'post-daemonize')
99
+ copy_framework_template( 'config', 'post-daemonize', 'readme' )
100
+ end
101
+ end
102
+
103
+ # Upgrade the Rakefile
104
+ task :rakefile do
105
+ copy_framework_template( 'Rakefile' )
106
+ end
107
+
108
+ # Upgrade the scripts
109
+ task :scripts do
110
+ %w{ console destroy generate }.each do |s|
111
+ copy_framework_template( "script", s )
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ def copy_framework_template( *args )
118
+ src_dir = File.join(DaemonKit.framework_root, 'app_generators', 'daemon_kit', 'templates')
119
+ cp File.join( src_dir, *args ), File.join( DaemonKit.root, *args )
120
+ end
@@ -0,0 +1,62 @@
1
+ require 'erb'
2
+
3
+ namespace :god do
4
+ desc "Generate a stub god config file template for the daemon"
5
+ task :template => 'environment' do
6
+ # Preserve local changes
7
+ if File.exists?( "#{DaemonKit.root}/config/god.erb" ) && ENV['FORCE'].nil?
8
+ puts "Template already exists, use FORCE=1 to overwrite."
9
+ exit 1
10
+ end
11
+
12
+ cp "#{DaemonKit.framework_root}/templates/god/god.erb", "#{DaemonKit.root}/config/god.erb"
13
+ end
14
+
15
+ desc "Parse the god config template into a god config file"
16
+ task :generate => 'environment' do
17
+
18
+ unless File.exists?( "#{DaemonKit.root}/config/god.erb" )
19
+ Rake::Task["god:template"].invoke
20
+ end
21
+
22
+ name = DaemonKit.configuration.daemon_name
23
+
24
+ File.open( "#{DaemonKit.root}/config/#{name}.god", "w+" ) do |f|
25
+ t = File.read( "#{DaemonKit.root}/config/god.erb" )
26
+ f.write( ERB.new( t ).result( binding ) )
27
+ end
28
+
29
+ puts "god config generated in config/#{name}.god"
30
+ end
31
+
32
+ desc "Load the god file into god"
33
+ task :load => 'environment' do
34
+ name = DaemonKit.configuration.daemon_name
35
+
36
+ sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god load #{DaemonKit.root}/config/#{name}.god"
37
+ end
38
+
39
+ desc "Refresh the god config file in the running god"
40
+ task :refresh => 'environment' do
41
+ name = DaemonKit.configuration.daemon_name
42
+
43
+ sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god unmonitor #{name}"
44
+ sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god remove #{name}"
45
+ sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god load #{DaemonKit.root}/config/#{name}.god"
46
+ sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god monitor #{name}"
47
+ end
48
+
49
+ desc "Start god monitoring of the config file"
50
+ task :monitor => 'environment' do
51
+ name = DaemonKit.configuration.daemon_name
52
+
53
+ sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god monitor #{name}"
54
+ end
55
+
56
+ desc "Stop god monitoring of the config file"
57
+ task :unmonitor => 'environment' do
58
+ name = DaemonKit.configuration.daemon_name
59
+
60
+ sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god unmonitor #{name}"
61
+ end
62
+ end