resque-uniq 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YjVjMDYxYzIxZTJkNGI4OTE1MDc1ZjgxMjAzZWQwYzMwNDZkZmJhNQ==
5
- data.tar.gz: !binary |-
6
- YWJmMzM3MzE3MjRjNGIxOTg5OWRiODFlMTA1ZDlkZTRiNTM4ZDkxYg==
2
+ SHA1:
3
+ metadata.gz: 40e69c1e3f78c813e847aabd6abd83d13baf8137
4
+ data.tar.gz: 8dc908ad095b39123a898f778e6e8aeeb0581b35
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YWMzOGI4ODE5ZmFjMzFlNzc3NGJkNTU0YjQ4OGI3NzUxYWVlZGRkMGY1OGJj
10
- YjRlNTZkMjYzZjQzNjUwODQzOTVjNmM3ODI0MDI3MmUwMTg4Yjg1NzM4NmY0
11
- Njk4YjkxMmE1ZGM1NGI2M2UyMzJiZTdlNmJiNWRmNDc0YzQ2YmI=
12
- data.tar.gz: !binary |-
13
- MDljNjY1NzkyYjQwMWQ0OTQ4YzliNDNjNjU1ZTA2NTdjNTVhYzgwNDZjYzc2
14
- NWY2ZThjNzhjZTFkMDA2N2YxMWU3ODE4NjM4ZDRkZDg5OWZlNTVlZDQ5NmZm
15
- NzhkMjZhNDU1YmU3NzkyZjE4ZjExZDIzMGI0OGFiM2FlMDYzMDY=
6
+ metadata.gz: f6c86360697f52039cf02bfe318a22426243365866a368c266a68b96bd8eae7bbea4efb77eeeae0486fcfd06ad038eb38a5251ec68e035409426ec52851d7004
7
+ data.tar.gz: 3965ee5e0a1dbb2dd55b3f1ea6b4a0ea86f33fea2b395041f487ba939671a8bd350e6b398f1fa5337675db3bf82a0f733b3953685c6171309388511359d457c2
@@ -1,3 +1,3 @@
1
1
  module ResqueUniq
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -20,6 +20,29 @@ module Resque
20
20
  rlock.sub(/^#{RUN_LOCK_NAME_PREFIX}/, '')
21
21
  end
22
22
 
23
+ def payload_class(camel_cased_word)
24
+ camel_cased_word = camel_cased_word.to_s
25
+
26
+ if camel_cased_word.include?('-')
27
+ camel_cased_word = classify(camel_cased_word)
28
+ end
29
+
30
+ names = camel_cased_word.split('::')
31
+ names.shift if names.empty? || names.first.empty?
32
+
33
+ constant = Object
34
+ names.each do |name|
35
+ args = Module.method(:const_get).arity != 1 ? [false] : []
36
+
37
+ if constant.const_defined?(name, *args)
38
+ constant = constant.const_get(name)
39
+ else
40
+ constant = constant.const_missing(name)
41
+ end
42
+ end
43
+ constant
44
+ end
45
+
23
46
  def stale_lock?(lock)
24
47
  return false unless get_lock(lock)
25
48
 
@@ -29,7 +52,7 @@ module Resque
29
52
  Resque.working.map {|w| w.job }.map do |item|
30
53
  begin
31
54
  payload = item['payload']
32
- klass = Resque::Job.constantize(payload['class'])
55
+ klass = payload_class(payload['class'])
33
56
  args = payload['args']
34
57
  return false if rlock == klass.run_lock(*args)
35
58
  rescue NameError
@@ -104,6 +127,8 @@ module Resque
104
127
  s = []
105
128
  obj.each { |a| s << obj_to_string(a) }
106
129
  s.to_s
130
+ when Time
131
+ obj.to_i
107
132
  else
108
133
  obj.to_s
109
134
  end
@@ -25,6 +25,15 @@ class UniqueJobTest < Test::Unit::TestCase
25
25
 
26
26
  class ExtendedAutoExpireLockJob < AutoexpireLockJobBase ; end
27
27
 
28
+ class RepeaterJob
29
+ extend Resque::Plugins::UniqueJob
30
+ @queue = :job_test
31
+
32
+ def self.perform(param)
33
+ Resque.enqueue(RepeaterJob, "hello")
34
+ end
35
+ end
36
+
28
37
  def setup
29
38
  Resque.redis.flushdb
30
39
  end
@@ -97,4 +106,34 @@ class UniqueJobTest < Test::Unit::TestCase
97
106
  Resque.enqueue(AutoexpireLockJob, 123)
98
107
  assert_equal 1, Resque.size(Resque.queue_from_class(AutoexpireLockJob))
99
108
  end
109
+
110
+ def test_payload_class
111
+ klass = Job.payload_class("UniqueJobTest::AutoexpireLockJob")
112
+ assert_equal klass, AutoexpireLockJob
113
+ end
114
+
115
+ def test_not_stale_lock
116
+ Resque.redis.set(Job.lock("hello"), Time.now.to_i)
117
+ assert_equal false, Job.stale_lock?(Job.lock("hello"))
118
+ end
119
+
120
+ def test_stale_lock
121
+ Resque.redis.set(Job.lock("hello"), Time.now.to_i)
122
+ Resque.redis.set(Job.run_lock("hello"), Time.now.to_i)
123
+ assert_equal true, Job.stale_lock?(Job.lock("hello"))
124
+ end
125
+
126
+ def test_cant_enqueue_another_job_if_worker_still_working
127
+ queue = Resque.queue_from_class(RepeaterJob)
128
+ Resque.enqueue(RepeaterJob, "hello")
129
+ assert_equal 1, Resque.size(queue)
130
+
131
+ worker = Resque::Worker.new(queue)
132
+ job = worker.reserve
133
+ worker.register_worker
134
+ worker.working_on job
135
+ worker.perform(job)
136
+
137
+ assert_equal 0, Resque.size(queue), "Expected queue to be empty"
138
+ end
100
139
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-uniq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trung Duc Tran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,8 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gitignore
21
- - .travis.yml
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
22
  - Gemfile
23
23
  - LICENSE
24
24
  - README.md
@@ -37,17 +37,17 @@ require_paths:
37
37
  - lib
38
38
  required_ruby_version: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ! '>='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project:
50
- rubygems_version: 2.1.11
50
+ rubygems_version: 2.2.0
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: A Resque plugin to ensure only one job instance is queued or running at a