hirefire-resource 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hirefire-resource.gemspec +1 -1
- data/lib/hirefire-resource.rb +1 -1
- data/lib/hirefire/macro/bunny.rb +80 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 871488e23cf718f9e13eb8bddd89098fb9951b82
|
4
|
+
data.tar.gz: ee697e01f7d2456d7f9d803878ddce0f8a8d35f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afd1042bac8694192d66e19cc2058236cd26bff7796979a83beea0c56fa269e2116ce2b94e2ecefd10dd2a08c5fa919a977caa14ef75aa915b57276728395c03
|
7
|
+
data.tar.gz: ac30b7c4403cab11501e67f75f12b9bd168ee296a36f681a6ca7da22b9815ff8243b2d672c2e792478c21a194aa881cb4b5732cb46eadd1da50448b5e8b71519
|
data/hirefire-resource.gemspec
CHANGED
data/lib/hirefire-resource.rb
CHANGED
@@ -6,7 +6,7 @@ HIREFIRE_PATH = File.expand_path("../hirefire", __FILE__)
|
|
6
6
|
require "#{HIREFIRE_PATH}/#{file}"
|
7
7
|
end
|
8
8
|
|
9
|
-
%w[delayed_job resque sidekiq qu qc].each do |file|
|
9
|
+
%w[delayed_job resque sidekiq qu qc bunny].each do |file|
|
10
10
|
require "#{HIREFIRE_PATH}/macro/#{file}"
|
11
11
|
end
|
12
12
|
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module HireFire
|
4
|
+
module Macro
|
5
|
+
module Bunny
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Returns the job quantity for the provided queue(s).
|
9
|
+
#
|
10
|
+
# @example Bunny Macro Usage
|
11
|
+
#
|
12
|
+
# # all queues using existing RabbitMQ connection.
|
13
|
+
# HireFire::Macro::Bunny.queue("queue1", "queue2", :connection => connection)
|
14
|
+
#
|
15
|
+
# # all queues using new RabbitMQ connection.
|
16
|
+
# HireFire::Macro::Bunny.queue("queue1", "queue2", :amqp_url => url)
|
17
|
+
#
|
18
|
+
# # all non-durable queues using new RabbitMQ connection.
|
19
|
+
# HireFire::Macro::Bunny.queue("queue1", "queue2", :amqp_url => url, :durable => false)
|
20
|
+
#
|
21
|
+
# @param [Array] queues provide one or more queue names, or none for "all".
|
22
|
+
# Last argument can pass in a Hash containing :connection => rabbitmq_connection or :amqp => :rabbitmq_url
|
23
|
+
# @return [Integer] the number of jobs in the queue(s).
|
24
|
+
#
|
25
|
+
def queue(*queues)
|
26
|
+
require "bunny"
|
27
|
+
|
28
|
+
queues.flatten!
|
29
|
+
|
30
|
+
if queues.last.is_a?(Hash)
|
31
|
+
options = queues.pop
|
32
|
+
else
|
33
|
+
options = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
if options[:durable].nil?
|
37
|
+
options[:durable] = true
|
38
|
+
end
|
39
|
+
|
40
|
+
if options[:connection]
|
41
|
+
connection = options[:connection]
|
42
|
+
|
43
|
+
channel = nil
|
44
|
+
begin
|
45
|
+
channel = connection.create_channel
|
46
|
+
return count_messages(channel, queues, options)
|
47
|
+
ensure
|
48
|
+
if channel
|
49
|
+
channel.close
|
50
|
+
end
|
51
|
+
end
|
52
|
+
elsif options[:amqp_url]
|
53
|
+
connection = ::Bunny.new(options[:amqp_url])
|
54
|
+
begin
|
55
|
+
connection.start
|
56
|
+
channel = connection.create_channel
|
57
|
+
return count_messages(channel, queues, options)
|
58
|
+
ensure
|
59
|
+
if channel
|
60
|
+
channel.close
|
61
|
+
end
|
62
|
+
|
63
|
+
connection.close
|
64
|
+
end
|
65
|
+
else
|
66
|
+
raise %{Must pass in :connection => rabbitmq_connection or :amqp_url => url\n} +
|
67
|
+
%{For example: HireFire::Macro::Bunny.queue("queue1", :connection => rabbitmq_connection}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def count_messages(channel, queue_names, options)
|
72
|
+
queue_names.inject(0) do |sum, queue_name|
|
73
|
+
queue = channel.queue(queue_name, :durable => options[:durable])
|
74
|
+
sum + queue.message_count
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirefire-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Load-based scaling, schedule-based scaling, dyno crash recovery, for
|
14
14
|
web- and worker dynos.
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- hirefire-resource.gemspec
|
29
29
|
- lib/hirefire-resource.rb
|
30
30
|
- lib/hirefire/cli.rb
|
31
|
+
- lib/hirefire/macro/bunny.rb
|
31
32
|
- lib/hirefire/macro/delayed_job.rb
|
32
33
|
- lib/hirefire/macro/qc.rb
|
33
34
|
- lib/hirefire/macro/qu.rb
|