elecnix-workling 0.4.2 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/CHANGES.markdown +10 -0
  2. data/README.markdown +161 -4
  3. data/bin/workling_client +28 -0
  4. metadata +3 -75
  5. data/lib/rude_q/client.rb +0 -11
  6. data/lib/workling.rb +0 -150
  7. data/lib/workling/base.rb +0 -71
  8. data/lib/workling/clients/amqp_client.rb +0 -56
  9. data/lib/workling/clients/base.rb +0 -57
  10. data/lib/workling/clients/memcache_queue_client.rb +0 -83
  11. data/lib/workling/discovery.rb +0 -14
  12. data/lib/workling/remote.rb +0 -42
  13. data/lib/workling/remote/invokers/base.rb +0 -124
  14. data/lib/workling/remote/invokers/basic_poller.rb +0 -41
  15. data/lib/workling/remote/invokers/eventmachine_subscriber.rb +0 -41
  16. data/lib/workling/remote/invokers/threaded_poller.rb +0 -140
  17. data/lib/workling/remote/runners/backgroundjob_runner.rb +0 -35
  18. data/lib/workling/remote/runners/base.rb +0 -42
  19. data/lib/workling/remote/runners/client_runner.rb +0 -45
  20. data/lib/workling/remote/runners/not_remote_runner.rb +0 -23
  21. data/lib/workling/remote/runners/rudeq_runner.rb +0 -23
  22. data/lib/workling/remote/runners/spawn_runner.rb +0 -38
  23. data/lib/workling/remote/runners/starling_runner.rb +0 -13
  24. data/lib/workling/return/store/base.rb +0 -42
  25. data/lib/workling/return/store/iterator.rb +0 -24
  26. data/lib/workling/return/store/memory_return_store.rb +0 -26
  27. data/lib/workling/return/store/rudeq_return_store.rb +0 -24
  28. data/lib/workling/return/store/starling_return_store.rb +0 -31
  29. data/lib/workling/routing/base.rb +0 -13
  30. data/lib/workling/routing/class_and_method_routing.rb +0 -55
  31. data/lib/workling/rudeq.rb +0 -7
  32. data/lib/workling/rudeq/client.rb +0 -17
  33. data/lib/workling/rudeq/poller.rb +0 -116
  34. data/test/class_and_method_routing_test.rb +0 -18
  35. data/test/clients/memory_queue_client.rb +0 -36
  36. data/test/discovery_test.rb +0 -13
  37. data/test/invoker_basic_poller_test.rb +0 -29
  38. data/test/invoker_eventmachine_subscription_test.rb +0 -26
  39. data/test/invoker_threaded_poller_test.rb +0 -34
  40. data/test/memcachequeue_client_test.rb +0 -36
  41. data/test/memory_return_store_test.rb +0 -32
  42. data/test/mocks/client.rb +0 -9
  43. data/test/mocks/logger.rb +0 -5
  44. data/test/mocks/rude_queue.rb +0 -9
  45. data/test/mocks/spawn.rb +0 -5
  46. data/test/not_remote_runner_test.rb +0 -11
  47. data/test/remote_runner_test.rb +0 -58
  48. data/test/rescue_test.rb +0 -24
  49. data/test/return_store_test.rb +0 -24
  50. data/test/rudeq_client_test.rb +0 -30
  51. data/test/rudeq_poller_test.rb +0 -14
  52. data/test/rudeq_return_store_test.rb +0 -20
  53. data/test/rudeq_runner_test.rb +0 -22
  54. data/test/runners/thread_runner.rb +0 -22
  55. data/test/spawn_runner_test.rb +0 -10
  56. data/test/starling_return_store_test.rb +0 -29
  57. data/test/starling_runner_test.rb +0 -8
  58. data/test/test_helper.rb +0 -50
  59. data/test/workers/analytics/invites.rb +0 -10
  60. data/test/workers/util.rb +0 -25
data/CHANGES.markdown CHANGED
@@ -1,3 +1,13 @@
1
+ Version 0.4.8, 07.05.2009
2
+ - implemented XMPP listener (experimental)
3
+ - implemented method for explicitly naming queues, this is useful in conjunction with the XMPP listener
4
+ - rewrote the workling_client script, now allows specifying configuration options on the command line. Makes it easier to manage workling instances in production, and allows running worklings for multiple apps on one machine
5
+ - integrated support for custom exception notifications
6
+
7
+ Version 0.4.2.3, 31.01.2009
8
+ - introduced Workling.raises_exceptions. by default, this is true in test and development to help with bug tracking.
9
+ - added :threaded as the default spawn runner for test and development. helps problem tracing.
10
+
1
11
  Version 0.4.2.2, 29.11.08
2
12
  - turned Workling.load_path into an Array.
3
13
 
data/README.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # *digitalhobbit/workling Fork Notes*
2
+
3
+ *This particular Workling fork provides an SQS Client. See instructions below.*
4
+
1
5
  # Workling
2
6
 
3
7
  Workling gives your Rails App a simple API that you can use to make code run in the background, outside of the your request.
@@ -56,7 +60,11 @@ Calling `async_my_method` on the worker class will trigger background work. This
56
60
 
57
61
  If an exception is raised in your Worker, it will not be propagated to the calling code by workling. This is because the code is called asynchronously, meaning that exceptions may be raised after the calling code has already returned. If you need your calling code to handle exceptional situations, you have to pass the error into the return store.
58
62
 
59
- Workling does log all exceptions that propagate out of the worker methods.
63
+ Workling does log all exceptions that propagate out of the worker methods.
64
+
65
+ Furthermore you can provide custom exception handling by defining the
66
+ notify_exception(exception, method, options)
67
+ in your worker class. If it is present it will be called for every exception
60
68
 
61
69
  ## Logging with Workling
62
70
 
@@ -64,6 +72,52 @@ Workling does log all exceptions that propagate out of the worker methods.
64
72
 
65
73
  logger.info("about to moo.")
66
74
 
75
+ ## Running Workling (in production)
76
+
77
+ The workling daemon can be invoked using the command
78
+
79
+ script/workling_client run
80
+
81
+ This will make it run in the development environment, with the default settings unless overridden in your development.rb (see below)
82
+
83
+ For production use the script takes a couple of options
84
+
85
+ script/workling_client <daemon_options> -- <app_options>
86
+
87
+ The daemon_options configure the runtime environment of the daemon and can be one of the following options:
88
+
89
+ --app-name APP_NAME
90
+ --dir DIR
91
+ --monitor
92
+ --ontop
93
+
94
+ The app-name option is useful if you want to run worklings for multiple Rails apps on the same machine. Each app will need to have its unique name.
95
+ The monitor option should not be specified if you are using Monit or god.
96
+ The dir options specifies where the logs and the pid files are saved.
97
+
98
+ The app_options allow you to specify the configuration of the workling interfaces via the command line:
99
+
100
+ --client CLIENT
101
+ --invoker INVOKER
102
+ --routing ROUTING
103
+ --load-path LOADPATH
104
+ --environment ENVIRONMENT
105
+
106
+ The client, invoker and routing params take the full class names of the relevant plugin classes. load-path allows overriding where workling looks for workers and environment should be self explanatory.
107
+
108
+ The following is a sample of how workling_client can be used with god and AMQP:
109
+
110
+ God.watch do |w|
111
+ script = "cd #{RAILS_ROOT} && workling_client"
112
+ w.name = "myapp-workling"
113
+ w.start = "#{script} start -a myapp-workling -- -e production -i Workling::Remote::Invokers::EventmachineSubscriber -c Workling::Clients::AmqpClient"
114
+ w.restart = "#{script} restart -a myapp-workling -- -e production -i Workling::Remote::Invokers::EventmachineSubscriber -c Workling::Clients::AmqpClient"
115
+ w.stop = "#{script} stop -a myapp-workling"
116
+
117
+ w.pid_file = "#{RAILS_ROOT}/log/myapp-workling.pid"
118
+ end
119
+
120
+
67
121
  ## What should I know about the Spawn Runner?
68
122
 
69
123
  Workling automatically detects and uses Spawn, if installed. Spawn basically forks Rails every time you invoke a workling. To see what sort of characteristics this has, go into script/console, and run this:
@@ -75,9 +129,20 @@ You'll see that this executes pretty much instantly. Run 'top' in another termin
75
129
 
76
130
  You cannot run your workers on a remote machine or cluster them with spawn. You also have no persistence: if you've fired of a lot of work and everything dies, there's no way of picking up where you left off.
77
131
 
78
- # Using the Starling runner
79
132
 
80
- If you want cross machine jobs with low latency and a low memory overhead, you might want to look into using the Starling Runner.
133
+ ## Gohanlon addition
134
+
135
+ To use Workling with Spawn, you can safely delete the config/workling.yml file generated by 'script/plugin install'.
136
+
137
+ Also in your environment.rb file the following are useful
138
+
139
+ # Run all jobs to be executed in the foreground
140
+ # Workling::Remote.dispatcher = Workling::Remote::Runners::NotRemoteRunner.new
141
+
142
+ # Execute jobs in a forked process using Spawn
143
+ Workling::Remote::Runners::SpawnRunner.options = { :method => :spawn }
144
+ Workling::Remote.dispatcher = Workling::Remote::Runners::SpawnRunner.new
145
+
81
146
 
82
147
  ## Installing Starling
83
148
 
@@ -219,6 +284,96 @@ Workling will now automatically detect and use Bj, unless you have also installe
219
284
 
220
285
  Workling::Remote.dispatcher = Workling::Remote::Runners::BackgroundjobRunner.new
221
286
 
287
+
288
+ # Using XMPP listener
289
+
290
+ NOTE: this code is highly experimental. It was implemented in order to facilitate the async communication between multiple Rails app running in the same domain/datacentre. However it is no longer in production use, since the setup proved to be both too complex to maintain and quite unreliable. The AMQP support turned out to be much more appropriate.
291
+ I'm putting this here as a starting base for someone interested in using XMPP in such a way. Contact me at derfred on github if you want pointers.
292
+
293
+ this client requires the xmpp4r gem
294
+
295
+ in the config/environments/development.rb file (or production.rb etc)
296
+
297
+ Workling::Remote::Runners::ClientRunner.client = Workling::Clients::XmppClient.new
298
+ Workling::Remote.dispatcher = Workling::Remote::Runners::ClientRunner.new # dont use the standard runner
299
+ Workling::Remote.invoker = Workling::Remote::Invokers::LoopedSubscriber # does not work with the EventmachineSubscriber Invoker
300
+
301
+ furthermore in the workling.yml file you need to set up the server details for your XMPP server
302
+
303
+ development:
304
+ listens_on: "localhost:22122"
305
+ jabber_id: "sub@localhost/laptop"
306
+ jabber_server: "localhost"
307
+ jabber_password: "sub"
308
+ jabber_service: "pubsub.derfredtop.local"
309
+
310
+ for details on how to configure your XMPP server (ejabberd) check out the following howto:
311
+
312
+ http://keoko.wordpress.com/2008/12/17/xmpp-pubsub-with-ejabberd-and-xmpp4r/
313
+
314
+
315
+ finally you need to expose your worker methods to XMPP nodes like so:
316
+
317
+ class NotificationWorker < Workling::Base
318
+
319
+ expose :receive_notification, :as => "/home/localhost/pub/sub"
320
+
321
+ def receive_notification(input)
322
+ # something here
323
+ end
324
+
325
+ end
326
+
327
+ # Using SQS
328
+
329
+ If you're running on Amazon EC2, you may want to leverage SQS (Simple Queue Service) to benefit from this highly scalable queue implementation without having to install any software.
330
+
331
+ The SQS Client namespaces queues with an optional prefix as well as with the Rails environment, allowing us to distinguish between production and staging queues, for example. Queues are automatically created the first time they are accessed.
332
+
333
+ Configuring Workling to use SQS is very straightforward and requires no additional software, with the exception of the RightAws gem.
334
+
335
+ ## Installing the SQS Client
336
+
337
+ Install the RightAws gem:
338
+
339
+ 1. sudo gem install right_aws
340
+
341
+ Configure Workling to use the SqsClient. Add this to your environment:
342
+
343
+ Workling::Remote.dispatcher = Workling::Remote::Runners::ClientRunner.new
344
+ Workling::Remote.dispatcher.client = Workling::Clients::SqsClient.new
345
+
346
+ Add your AWS key id and secret key to workling.yml:
347
+
348
+ production:
349
+ sqs_options:
350
+ aws_access_key_id: <your AWS access key id>
351
+ aws_secret_access_key: <your AWS secret access key>
352
+
353
+ You can optionally override the following settings, although the defaults
354
+ will likely be sufficient:
355
+
356
+ # Queue names consist of an optional prefix, followed by the environment
357
+ # and the name of the key.
358
+ prefix: foo_
359
+
360
+ # The number of SQS messages to retrieve at once. The maximum and default
361
+ # value is 10.
362
+ messages_per_req: 10
363
+
364
+ # The SQS visibility timeout for retrieved messages. Defaults to 30 seconds.
365
+ visibility_timeout: 30
366
+
367
+ Now start the Workling Client:
368
+
369
+ 1 ./script/workling_client start
370
+
371
+ You're good.
372
+
373
+ ## Limitations
374
+
375
+ SQS messages need to be explicitly deleted from the queue. Otherwise, they will reappear after the visibility timeout. The SQS client currently deletes a message immediately before handing it to a worker, assuming that it will be processed successfully. A more robust implementation (which would require additional hooks in the Workling framework) would be to defer the deletion until after the message was successfully processed, allowing us to retry the message processing in case of an error.
376
+
222
377
  # Progress indicators and return stores
223
378
 
224
379
  Your worklings can write back to a return store. This allows you to write progress indicators, or access results from your workling. As above, this is fairly slim. Again, you can swap in any return store implementation you like without changing your code. They all behave like memcached. For tests, there is a memory return store, for production use there is currently a starling return store. You can easily add a new return store (over the database for instance) by subclassing `Workling::Return::Store::Base`. Configure it like this in your test environment:
@@ -365,11 +520,13 @@ Next, inside of `listen`, we need to iterate through all defined routes. There i
365
520
 
366
521
  That's it! We now have a more effective Invoker.
367
522
 
523
+
524
+
368
525
  # Contributors
369
526
 
370
527
  The following people contributed code to workling so far. Many thanks :) If I forgot anybody, I aplogise. Just drop me a note and I'll add you to the project so that you can amend this!
371
528
 
372
- Anybody who contributes fixes (with tests), or new functionality (whith tests) which is pulled into the main project, will also be be added to the project.
529
+ Anybody who contributes fixes (with tests), or new functionality (with tests) which is pulled into the main project, will also be be added to the project.
373
530
 
374
531
  * Andrew Carter (ascarter)
375
532
  * Chris Gaffney (gaffneyc)
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'daemons'
4
+ require 'workling_server'
5
+
6
+ daemon_options = {
7
+ :app_name => "workling",
8
+ :dir_mode => :normal,
9
+ :dir => File.join(Dir.pwd, 'log'),
10
+ :log_output => true,
11
+ :multiple => false,
12
+ :backtrace => true,
13
+ :monitor => false
14
+ }.merge(WorklingServer.parse_daemon_options(ARGV))
15
+
16
+ workling_options = {
17
+ :client_class => "Workling::Clients::MemcacheQueueClient",
18
+ :invoker_class => "Workling::Remote::Invokers::ThreadedPoller",
19
+ :routing_class => "Workling::Routing::ClassAndMethodRouting",
20
+ :rails_root => Dir.pwd,
21
+ :load_path => [ 'app/workers/**/*.rb' ],
22
+ :rails_env => (ENV['RAILS_ENV'] || "development").dup
23
+ }.merge(WorklingServer.parse_workling_options(ARGV))
24
+
25
+ Daemons.run_proc(daemon_options[:app_name], daemon_options) do
26
+ Dir.chdir(workling_options[:rails_root])
27
+ WorklingServer.run(workling_options)
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elecnix-workling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rany Keddo
@@ -15,8 +15,8 @@ dependencies: []
15
15
 
16
16
  description: easily do background work in rails, without commiting to a particular runner. comes with starling, bj and spawn runners.
17
17
  email: nicolas@marchildon.net
18
- executables: []
19
-
18
+ executables:
19
+ - workling_client
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files: []
@@ -26,78 +26,6 @@ files:
26
26
  - VERSION.yml
27
27
  - README.markdown
28
28
  - TODO.markdown
29
- - lib/workling.rb
30
- - lib/rude_q
31
- - lib/rude_q/client.rb
32
- - lib/tasks
33
- - lib/workling
34
- - lib/workling/remote.rb
35
- - lib/workling/rudeq.rb
36
- - lib/workling/remote
37
- - lib/workling/remote/runners
38
- - lib/workling/remote/runners/rudeq_runner.rb
39
- - lib/workling/remote/runners/not_remote_runner.rb
40
- - lib/workling/remote/runners/backgroundjob_runner.rb
41
- - lib/workling/remote/runners/base.rb
42
- - lib/workling/remote/runners/starling_runner.rb
43
- - lib/workling/remote/runners/client_runner.rb
44
- - lib/workling/remote/runners/spawn_runner.rb
45
- - lib/workling/remote/invokers
46
- - lib/workling/remote/invokers/base.rb
47
- - lib/workling/remote/invokers/basic_poller.rb
48
- - lib/workling/remote/invokers/eventmachine_subscriber.rb
49
- - lib/workling/remote/invokers/threaded_poller.rb
50
- - lib/workling/rudeq
51
- - lib/workling/rudeq/client.rb
52
- - lib/workling/rudeq/poller.rb
53
- - lib/workling/routing
54
- - lib/workling/routing/base.rb
55
- - lib/workling/routing/class_and_method_routing.rb
56
- - lib/workling/base.rb
57
- - lib/workling/discovery.rb
58
- - lib/workling/clients
59
- - lib/workling/clients/memcache_queue_client.rb
60
- - lib/workling/clients/base.rb
61
- - lib/workling/clients/amqp_client.rb
62
- - lib/workling/return
63
- - lib/workling/return/store
64
- - lib/workling/return/store/iterator.rb
65
- - lib/workling/return/store/starling_return_store.rb
66
- - lib/workling/return/store/base.rb
67
- - lib/workling/return/store/memory_return_store.rb
68
- - lib/workling/return/store/rudeq_return_store.rb
69
- - test/invoker_eventmachine_subscription_test.rb
70
- - test/discovery_test.rb
71
- - test/spawn_runner_test.rb
72
- - test/starling_runner_test.rb
73
- - test/not_remote_runner_test.rb
74
- - test/starling_return_store_test.rb
75
- - test/rudeq_client_test.rb
76
- - test/mocks
77
- - test/mocks/logger.rb
78
- - test/mocks/spawn.rb
79
- - test/mocks/client.rb
80
- - test/mocks/rude_queue.rb
81
- - test/runners
82
- - test/runners/thread_runner.rb
83
- - test/clients
84
- - test/clients/memory_queue_client.rb
85
- - test/invoker_basic_poller_test.rb
86
- - test/rudeq_poller_test.rb
87
- - test/remote_runner_test.rb
88
- - test/test_helper.rb
89
- - test/workers
90
- - test/workers/analytics
91
- - test/workers/analytics/invites.rb
92
- - test/workers/util.rb
93
- - test/memcachequeue_client_test.rb
94
- - test/rescue_test.rb
95
- - test/class_and_method_routing_test.rb
96
- - test/rudeq_return_store_test.rb
97
- - test/invoker_threaded_poller_test.rb
98
- - test/return_store_test.rb
99
- - test/memory_return_store_test.rb
100
- - test/rudeq_runner_test.rb
101
29
  has_rdoc: true
102
30
  homepage: http://github.com/elecnix/workling
103
31
  post_install_message:
data/lib/rude_q/client.rb DELETED
@@ -1,11 +0,0 @@
1
- #
2
- # A RudeQ client that behvaes somewhat like memcache-client
3
- #
4
- module RudeQ
5
- class Client
6
- def initialize(*args); super(); end
7
- def set(key, value); RudeQueue.set(key, value); end;
8
- def get(key); RudeQueue.get(key); end;
9
- def stats; ActiveRecord::Base.connection; end
10
- end
11
- end
data/lib/workling.rb DELETED
@@ -1,150 +0,0 @@
1
- #
2
- # I can haz am in your Workling are belong to us!
3
- #
4
- module Workling
5
- class WorklingError < StandardError; end
6
- class WorklingNotFoundError < WorklingError; end
7
- class WorklingConnectionError < WorklingError; end
8
- class QueueserverNotFoundError < WorklingError
9
- def initialize
10
- super "config/workling.yml configured to connect to queue server on #{ Workling.config[:listens_on] } for this environment. could not connect to queue server on this host:port. for starling users: pass starling the port with -p flag when starting it. If you don't want to use Starling, then explicitly set Workling::Remote.dispatcher (see README for an example)"
11
- end
12
- end
13
-
14
- class ConfigurationError < WorklingError
15
- def initialize
16
- super File.exist?(File.join(RAILS_ROOT, 'config', 'starling.yml')) ?
17
- "config/starling.yml has been depracated. rename your config file to config/workling.yml then try again!" :
18
- "config/workling.yml could not be loaded. check out README.markdown to see what this file should contain. "
19
- end
20
- end
21
-
22
- mattr_accessor :load_path
23
- @@load_path = [ File.expand_path(File.join(File.dirname(__FILE__), '../../../../app/workers')) ]
24
- VERSION = "0.4.2.2"
25
-
26
- #
27
- # determine the runner to use if nothing is specifically set. workling will try to detect
28
- # starling, spawn, or bj, in that order. if none of these are found, notremoterunner will
29
- # be used.
30
- #
31
- # this can be overridden by setting Workling::Remote.dispatcher, eg:
32
- # Workling::Remote.dispatcher = Workling::Remote::Runners::StarlingRunner.new
33
- #
34
- def self.default_runner
35
- if RAILS_ENV == "test"
36
- Workling::Remote::Runners::NotRemoteRunner.new
37
- elsif starling_installed?
38
- Workling::Remote::Runners::StarlingRunner.new
39
- elsif spawn_installed?
40
- Workling::Remote::Runners::SpawnRunner.new
41
- elsif bj_installed?
42
- Workling::Remote::Runners::BackgroundjobRunner.new
43
- else
44
- Workling::Remote::Runners::NotRemoteRunner.new
45
- end
46
- end
47
-
48
- #
49
- # gets the worker instance, given a class. the optional method argument will cause an
50
- # exception to be raised if the worker instance does not respoind to said method.
51
- #
52
- def self.find(clazz, method = nil)
53
- begin
54
- inst = clazz.to_s.camelize.constantize.new
55
- rescue NameError
56
- raise_not_found(clazz, method)
57
- end
58
- raise_not_found(clazz, method) if method && !inst.respond_to?(method)
59
- inst
60
- end
61
-
62
- # returns Workling::Return::Store.instance.
63
- def self.return
64
- Workling::Return::Store.instance
65
- end
66
-
67
- # is spawn installed?
68
- def self.spawn_installed?
69
- begin
70
- require 'spawn'
71
- rescue LoadError
72
- end
73
-
74
- Object.const_defined? "Spawn"
75
- end
76
-
77
- # is starling installed?
78
- def self.starling_installed?
79
- begin
80
- require 'starling'
81
- rescue LoadError
82
- end
83
-
84
- Object.const_defined? "Starling"
85
- end
86
-
87
- # is bj installed?
88
- def self.bj_installed?
89
- Object.const_defined? "Bj"
90
- end
91
-
92
- # tries to load fiveruns-memcache-client. if this isn't found,
93
- # memcache-client is searched for. if that isn't found, don't do anything.
94
- def self.try_load_a_memcache_client
95
- begin
96
- gem 'fiveruns-memcache-client'
97
- require 'memcache'
98
- rescue Gem::LoadError
99
- begin
100
- gem 'memcache-client'
101
- require 'memcache'
102
- rescue Gem::LoadError
103
- Workling::Base.logger.info "WORKLING: couldn't find a memcache client - you need one for the starling runner. "
104
- end
105
- end
106
- end
107
-
108
- # attempts to load amqp and writes out descriptive error message if not present
109
- def self.try_load_an_amqp_client
110
- begin
111
- require 'mq'
112
- rescue Exception => e
113
- raise WorklingError.new(
114
- "WORKLING: couldn't find the ruby amqp client - you need it for the amqp runner. " \
115
- "Install from github: gem sources -a http://gems.github.com/ && sudo gem install tmm1-amqp "
116
- )
117
- end
118
- end
119
-
120
- #
121
- # returns a config hash. reads RAILS_ROOT/config/workling.yml
122
- #
123
- def self.config
124
- begin
125
- config_path = File.join(RAILS_ROOT, 'config', 'workling.yml')
126
- @@config ||= YAML.load_file(config_path)[RAILS_ENV || 'development'].symbolize_keys
127
- @@config[:memcache_options].symbolize_keys! if @@config[:memcache_options]
128
- @@config
129
- rescue
130
- # config files could not be read correctly
131
- raise ConfigurationError.new
132
- end
133
- end
134
-
135
- #
136
- # Raises exceptions thrown inside of the worker. normally, these are logged to
137
- # logger.error. it's easy to miss these log calls while developing, though.
138
- #
139
- mattr_accessor :raise_exceptions
140
- @@raise_exceptions = (RAILS_ENV == "test" || RAILS_ENV == "development")
141
-
142
- def self.raise_exceptions?
143
- @@raise_exceptions
144
- end
145
-
146
- private
147
- def self.raise_not_found(clazz, method)
148
- raise Workling::WorklingNotFoundError.new("could not find #{ clazz }:#{ method } workling. ")
149
- end
150
- end