resque_ranger 1.0.0.alpha.2 → 1.0.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/resque_ranger/core.rb +83 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmM4YjkyMDNlOGM1MjhkNWI1ODNkNmE2OTQ3MDI4ODlmNWYxN2RjMw==
4
+ MDI1ZDFjM2ZlYzdkOTdiZjBlMWU1NmM5Y2NlNTViN2E0MzM4Y2M1Ng==
5
5
  data.tar.gz: !binary |-
6
- NTg3ZTU2NWJiYWEzNmM0NzEyMmM5Y2NlMzg4MTRkZjRlYjY5ZTRlMg==
6
+ ZTZiMGU3YmU5YjY1Mzg1NWFhMTI3YzFjZGVjNWFiYjFmNTgyNjUwMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWIxOWNhNWY5MDA5OTk5YWQwZDNjYWI3Nzc5ZjI3NzQ3NzM4NTlkOTk5NTI3
10
- ODQzNTdkZjk0YTk4MGE4NzQwOGY5NWM3OWRiMTZiNGUwN2Y5NzBmOTUwODcx
11
- OTVjZDk1Nzc1MzIxMWMxMTk3OWZjZjhkMjVjMDg2ZmQ4Y2ZmZTg=
9
+ NjgzNjFlM2NkZTBlMTFjZjgzY2M4MmVjZWE1YmJiMzllNjIxNzVhNjEwNDlh
10
+ YTk3ZDUwMWY2ZjZlY2U4MmQ3NTViZDAzNGEzYTQyNmVlZmFjMGFmYzY1YTg4
11
+ NjM4ZWM0ODI3Yjk3MWZmOTcxMzE4MGY0N2FlZjU0NzY4ODliNDU=
12
12
  data.tar.gz: !binary |-
13
- OTVjNjhjYTExOTRkNGIxZmE4NGRiMzFjZTU4ZjgzN2ZlZDY3NTVkMGFlOGI3
14
- YWFhZmM4YTU0M2NkNGJhZjExZDZkZmU5YTE4ZjcyMGQxZWFkMTdmYWRjOGI2
15
- OGZmMzgzOGEyYjdkNTE1NjdmOGZkYWFjNzZhMzE2YWI3ZTAzNzI=
13
+ YmVlM2UyZWI5MTg5OGYzNjAzOTYyN2ZjYjk2MGIzNjFlYzNlMzJhYWQxNGRj
14
+ MjEzOWFkMmFjYmVlMzVjMDY1YTU1NmQ4NjNjYjJhODcyODNjZTFlZWYzNTE5
15
+ MjE2YWZmNWM2YTc1YjIxOGEzNzgzZjcxYmRhYzI2MGZkYjI0Zjk=
@@ -1,14 +1,41 @@
1
1
  require 'resque'
2
2
 
3
+ require 'json'
4
+
3
5
  module ResqueRanger
4
6
 
5
7
  def self.queues
6
- Resque.queues.map do |q|
7
- Queue.new(name: q)
8
- end
8
+ @queues ||= QueueManager.new
9
9
  end
10
10
 
11
11
 
12
+ class QueueManager
13
+ include Enumerable
14
+
15
+ def keys
16
+ Resque.queues
17
+ end
18
+
19
+ def key?(name)
20
+ Resque.queues.include?(name.to_s)
21
+ end
22
+
23
+ def [](name)
24
+ if self.key?(name)
25
+ Queue.new(name: name.to_s)
26
+ end
27
+ end
28
+
29
+
30
+ def each
31
+ return enum_for(:each) unless block_given?
32
+
33
+ self.keys.each do |k|
34
+ yield self[k]
35
+ end
36
+ end
37
+ end
38
+
12
39
  class Queue
13
40
 
14
41
  attr_reader :name, :redis
@@ -31,11 +58,64 @@ module ResqueRanger
31
58
  end
32
59
 
33
60
 
61
+ def raw_listing(index, &block)
62
+ block ||= ->(x){ x }
63
+
64
+ if index.is_a? Integer
65
+ redis.lrange(formal_name, index, index).map(&block).first
66
+ elsif index.is_a? Range
67
+ # FIXME: This will not work for "..." ranges
68
+ redis.lrange(formal_name, index.begin, index.end).map(&block)
69
+ else
70
+ raise ArgumentError.new("index must be either an Integer or a Range")
71
+ end
72
+ end
73
+
74
+ def [](index)
75
+ raw_listing(index) do |listing|
76
+ QueueEntry.create(listing)
77
+ end
78
+ end
79
+
80
+
34
81
  def to_s
35
82
  name
36
83
  end
37
84
 
38
85
  end
39
86
 
87
+
88
+ # Wrapper around a single queue entry
89
+ class QueueEntry
90
+
91
+ attr_reader :raw_data, :worker_name, :args
92
+
93
+ def initialize(options = {})
94
+ @raw_data = options.fetch(:raw_data)
95
+ @worker_name = options.fetch(:worker_name)
96
+ @args = options.fetch(:args)
97
+ end
98
+
99
+ def self.create(raw_data)
100
+ parsed_data = JSON.parse(raw_data)
101
+ self.new(
102
+ raw_data: raw_data,
103
+ worker_name: parsed_data["class"],
104
+ args: parsed_data["args"]
105
+ )
106
+ end
107
+
108
+
109
+ def to_s
110
+ "#{worker_name}.perform(...)"
111
+ end
112
+
113
+ def inspect
114
+ rendered_args = args.map(&:inspect).join(", ")
115
+ "#{worker_name}.perform(#{rendered_args})"
116
+ end
117
+
118
+ end
119
+
40
120
  end
41
121
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_ranger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.2
4
+ version: 1.0.0.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lauber