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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c16298e883736fa3c4315f45f950db05a403f059
4
- data.tar.gz: c91e96b0c536e0dd63c3598fcfc61101ec4ddbf5
3
+ metadata.gz: 0dc8c8daab36782b2f117c1f703ac0ec0e6217ca
4
+ data.tar.gz: 7f903d01ffd50319959385cc6da68ddc2b92f4e9
5
5
  SHA512:
6
- metadata.gz: bc3df9811a38cad2ec01248fdb328b9913035154c3d011c27812dfc4571c81c8eac8741c1ccf72ca0da1eb893649b137ed21217dfe0adbf836dc1a9bf533597e
7
- data.tar.gz: 639ce61e28aed3b1ce3a8ed649c857642edc91d2e02dd850229fa5029d1ab8ecf4f5145809b32c8283316d7c8f0eea52920ad28c0ac056f757fb950460661114
6
+ metadata.gz: aefa5f2172eb9f8cacc0c587e6452392a0d274bc227e63c6a1f6f7000c471a79cd960eec06e96a80dcbf92b62e6c7701fbae026bcb5b4ab8766ceac933e3ea7e
7
+ data.tar.gz: 9da1e9ad94c2dd86ef521b760ff2ecbf747ed219e281f16bcb9c4de0806ff10b361bea53cbf8c204e0a1fdfc8221474a16928e72101aabc6acf5577c26e821ba
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Resque::Aliasing
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/resque/aliasing`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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
- klass = ensure_klass klass_name
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, instance_variable_get(:@queue)
10
- klass.instance_variable_set :@destination, self
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
- raise "expected #{const.name} to be a #{klass.name}" unless const.kind_of? Module
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 @destination, *args
7
+ Resque.enqueue @resque_aliasing_destination, *args
8
8
  false
9
9
  end
10
10
 
11
11
  def perform *args
12
- Resque.enqueue @destination, *args
12
+ Resque.enqueue @resque_aliasing_destination, *args
13
13
  end
14
14
  end
15
15
 
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module Aliasing
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-aliasing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misha Conway