workling 0.4.9.8 → 0.4.9.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,6 +76,7 @@ module Workling
76
76
  def self.clients
77
77
  {
78
78
  'amqp' => Workling::Clients::AmqpClient,
79
+ 'amqp_bunny' => Workling::Clients::AmqpBunnyClient,
79
80
  'amqp_exchange' => Workling::Clients::AmqpExchangeClient,
80
81
  'memcache' => Workling::Clients::MemcacheQueueClient,
81
82
  'starling' => Workling::Clients::MemcacheQueueClient,
@@ -0,0 +1,59 @@
1
+ #
2
+ # An AMQP client based on the synchrounous Bunny library which
3
+ # is easier to use in many situations
4
+ #
5
+ module Workling
6
+ module Clients
7
+ class AmqpBunnyClient < Workling::Clients::BrokerBase
8
+
9
+ def self.load
10
+ begin
11
+ require 'bunny'
12
+ rescue LoadError => e
13
+ raise WorklingError.new("WORKLING: couldn't find the bunny amqp client")
14
+ end
15
+ end
16
+
17
+ # starts the client.
18
+ def connect
19
+ begin
20
+ @bunny = Bunny.new((Workling.config[:amqp_options] ||{}).symbolize_keys)
21
+ @bunny.start
22
+ rescue
23
+ raise WorklingError.new("Couldn't start bunny amqp client, ensure the AMQP server is running.")
24
+ end
25
+ end
26
+
27
+ # no need for explicit closing. when the event loop
28
+ # terminates, the connection is closed anyway.
29
+ def close
30
+ @bunny.stop
31
+ # normal amqp does not require stopping
32
+ end
33
+
34
+ # subscribe to a queue
35
+ def subscribe(key)
36
+ @bunny.queue(queue_for(key)).subscribe(:timeout => 30) do |value|
37
+ data = Marshal.load(value) rescue value
38
+ yield data
39
+ end
40
+ end
41
+
42
+ # request and retrieve work
43
+ def retrieve(key)
44
+ @bunny.queue(queue_for(key)).pop[:payload]
45
+ end
46
+
47
+ def request(key, value)
48
+ data = Marshal.dump(value)
49
+ @bunny.queue(queue_for(key)).publish(data)
50
+ end
51
+
52
+ private
53
+ def queue_for(key)
54
+ "#{Workling.config[:prefix]}#{key}"
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -2,6 +2,15 @@ require 'optparse'
2
2
 
3
3
  class WorklingDaemon
4
4
 
5
+ def self.running_as_daemon?
6
+ !!@running_as_daemon
7
+ end
8
+
9
+ def self.run_as_daemon!
10
+ @running_as_daemon = true
11
+ end
12
+
13
+
5
14
  def self.partition_options(args)
6
15
  daemon = []
7
16
  workling = []
@@ -92,6 +101,8 @@ class WorklingDaemon
92
101
 
93
102
 
94
103
  def self.run(options)
104
+ WorklingDaemon.run_as_daemon!
105
+
95
106
  boot_with options
96
107
  poller = initialize_workling(options)
97
108
 
@@ -103,7 +114,7 @@ class WorklingDaemon
103
114
  begin
104
115
  poller.listen
105
116
  ensure
106
- puts '** No Worklings found.' if Workling::Discovery.discovered.empty?
117
+ puts '** No Worklings found.' if Workling::Discovery.discovered_workers.empty?
107
118
  puts '** Exiting'
108
119
  end
109
120
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 4
8
8
  - 9
9
- - 8
10
- version: 0.4.9.8
9
+ - 9
10
+ version: 0.4.9.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rany Keddo
@@ -36,6 +36,7 @@ files:
36
36
  - lib/extensions/mattr_accessor.rb
37
37
  - lib/workling/base.rb
38
38
  - lib/workling/clients/amqp_client.rb
39
+ - lib/workling/clients/amqp_bunny_client.rb
39
40
  - lib/workling/clients/amqp_exchange_client.rb
40
41
  - lib/workling/clients/backgroundjob_client.rb
41
42
  - lib/workling/clients/base.rb