resque-aliasing 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +27 -4
- data/lib/resque/plugins/aliasing.rb +11 -4
- data/lib/resque/plugins/aliasing/aliased_job.rb +2 -2
- data/lib/resque/plugins/aliasing/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dc8c8daab36782b2f117c1f703ac0ec0e6217ca
|
4
|
+
data.tar.gz: 7f903d01ffd50319959385cc6da68ddc2b92f4e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aefa5f2172eb9f8cacc0c587e6452392a0d274bc227e63c6a1f6f7000c471a79cd960eec06e96a80dcbf92b62e6c7701fbae026bcb5b4ab8766ceac933e3ea7e
|
7
|
+
data.tar.gz: 9da1e9ad94c2dd86ef521b760ff2ecbf747ed219e281f16bcb9c4de0806ff10b361bea53cbf8c204e0a1fdfc8221474a16928e72101aabc6acf5577c26e821ba
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Resque::Aliasing
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Resque plugin that allows you to alias jobs to other jobs. Useful when you are renaming jobs or consolidating multiple jobs into one.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,32 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
If you ever want to rename a job, but are worried about versions of the old job still left in your resque queues, just alias it!
|
24
|
+
The below example illustrates basic usage after we have renamed a job from Workers::Processing::ProcessCustomer to
|
25
|
+
Workers::DiscombobulateCustomer.
|
26
|
+
|
27
|
+
class Workers::DiscombobulateCustomer
|
28
|
+
@queue = :low
|
29
|
+
|
30
|
+
extend Resque::Plugins::Aliasing
|
31
|
+
alias_job 'Workers::Processing::ProcessCustomer'
|
32
|
+
|
33
|
+
def self.perform(customer_id)
|
34
|
+
# discombobulating customer!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Any Workers::Processing::ProcessCustomer jobs remaining in the queue will just get enqueued as Workers::DiscombobulateCustomer jobs when they are eventually 'performed'.
|
39
|
+
Additionally, any attempt to enqueue a Workers::Processing::ProcessCustomer job will instead enqueue a Workers::DiscombobulateCustomer job.
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
26
49
|
|
27
50
|
## Development
|
28
51
|
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module Resque
|
2
2
|
module Plugins
|
3
3
|
module Aliasing
|
4
|
+
class UnexpectedConstant < ::StandardError; end;
|
5
|
+
|
4
6
|
def alias_job klass_name
|
5
|
-
|
7
|
+
klass_name = klass_name.name if klass_name.kind_of? Class
|
8
|
+
klass = ensure_klass klass_name.to_s
|
6
9
|
|
7
10
|
unless aliased_jobs[klass.name]
|
8
11
|
aliased_jobs[klass.name] = 1
|
9
|
-
klass.instance_variable_set :@queue,
|
10
|
-
klass.instance_variable_set :@
|
12
|
+
klass.instance_variable_set :@queue, "dummy_queue"
|
13
|
+
klass.instance_variable_set :@resque_aliasing_destination, self
|
11
14
|
klass.include AliasedJob
|
12
15
|
end
|
13
16
|
end
|
@@ -32,7 +35,11 @@ module Resque
|
|
32
35
|
def ensure_const parent, const_name, klass
|
33
36
|
if parent.const_defined? const_name
|
34
37
|
const = parent.const_get const_name
|
35
|
-
|
38
|
+
unless const.kind_of? klass
|
39
|
+
full_const_name = const_name
|
40
|
+
full_const_name = "#{parent.name}::#{full_const_name}" unless parent == Object
|
41
|
+
raise UnexpectedConstant, "Expected #{full_const_name} to be a #{klass.name}"
|
42
|
+
end
|
36
43
|
const
|
37
44
|
else
|
38
45
|
parent.const_set const_name, klass.new
|
@@ -4,12 +4,12 @@ module Resque
|
|
4
4
|
module AliasedJob
|
5
5
|
module ClassMethods
|
6
6
|
def before_enqueue *args
|
7
|
-
Resque.enqueue @
|
7
|
+
Resque.enqueue @resque_aliasing_destination, *args
|
8
8
|
false
|
9
9
|
end
|
10
10
|
|
11
11
|
def perform *args
|
12
|
-
Resque.enqueue @
|
12
|
+
Resque.enqueue @resque_aliasing_destination, *args
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|