resque_solo 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +42 -5
- data/lib/resque_ext/job.rb +2 -0
- data/lib/resque_ext/resque.rb +21 -0
- data/lib/resque_solo/queue.rb +8 -2
- data/lib/resque_solo/unique_job.rb +2 -0
- data/lib/resque_solo/version.rb +3 -1
- data/lib/resque_solo.rb +2 -0
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42df791660a5f4108b5832348ac269e28fbb6d112133083dd9cb4d69ca42e14a
|
4
|
+
data.tar.gz: 7e6736901c21f62746df7546feaa03fb859171ff059bf86f2471300a5473fadf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be28624643d67f66db4b6a24a162f141fc15435f9091f94e80a3e6b8849f05362e2ccd3a7f42c0226aade67818ce61031caabc3ad84fab7cf8b2e23db81af0cb
|
7
|
+
data.tar.gz: a295e26d4324f067d9798451fd466c07c0e0f9f29b5449af799b0b163f56d755823fea3432035c743a412b5718898dde490610045e96707b64f57505aadc0695
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ ResqueSolo is a resque plugin to add unique jobs to resque.
|
|
10
10
|
|
11
11
|
It is a re-write of [resque-loner](https://github.com/jayniz/resque-loner).
|
12
12
|
|
13
|
-
It requires resque 1.25 and works with ruby 2.
|
13
|
+
It requires resque 1.25 or greater and works with ruby 2.3 and later.
|
14
14
|
|
15
15
|
It removes the dependency on `Resque::Helpers`, which is deprecated for resque 2.0.
|
16
16
|
|
@@ -19,7 +19,14 @@ It removes the dependency on `Resque::Helpers`, which is deprecated for resque 2
|
|
19
19
|
Add the gem to your Gemfile:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem
|
22
|
+
gem "resque_solo"
|
23
|
+
```
|
24
|
+
|
25
|
+
To use with resque 2.0.0, which is unreleased as of 2018/7/24:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem "resque", git: "https://github.com/resque/resque"
|
29
|
+
gem "resque_solo"
|
23
30
|
```
|
24
31
|
|
25
32
|
## Usage
|
@@ -39,11 +46,11 @@ If you attempt to queue a unique job multiple times, it is ignored:
|
|
39
46
|
|
40
47
|
```
|
41
48
|
Resque.enqueue UpdateCat, 1
|
42
|
-
=>
|
49
|
+
=> true
|
43
50
|
Resque.enqueue UpdateCat, 1
|
44
|
-
=>
|
51
|
+
=> nil
|
45
52
|
Resque.enqueue UpdateCat, 1
|
46
|
-
=>
|
53
|
+
=> nil
|
47
54
|
Resque.size :cats
|
48
55
|
=> 1
|
49
56
|
Resque.enqueued? UpdateCat, 1
|
@@ -64,3 +71,33 @@ The `lock_after_execution_period` setting can be used to delay when the unique j
|
|
64
71
|
takes around 10 seconds, and you don't want to requeue another job until you are sure it is done,
|
65
72
|
you could set `lock_after_execution_period = 20`. Or if you never want to run a long running
|
66
73
|
job more than once per minute, set `lock_after_execution_period = 60`.
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class UpdateCat
|
77
|
+
include Resque::Plugins::UniqueJob
|
78
|
+
@queue = :cats
|
79
|
+
@lock_after_execution_period = 20
|
80
|
+
|
81
|
+
def self.perform(cat_id)
|
82
|
+
# do something
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
Clone this repository, then:
|
90
|
+
|
91
|
+
Run tests with resque 1.x locally:
|
92
|
+
|
93
|
+
```sh
|
94
|
+
bundle
|
95
|
+
bundle exec rake test
|
96
|
+
```
|
97
|
+
|
98
|
+
Test supported versions of resque locally:
|
99
|
+
|
100
|
+
```sh
|
101
|
+
appraisal install
|
102
|
+
appraisal rake test
|
103
|
+
```
|
data/lib/resque_ext/job.rb
CHANGED
data/lib/resque_ext/resque.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Resque
|
2
4
|
class << self
|
5
|
+
# Override
|
6
|
+
# https://github.com/resque/resque/blob/master/lib/resque.rb
|
7
|
+
def enqueue_to(queue, klass, *args)
|
8
|
+
# Perform before_enqueue hooks. Don't perform enqueue if any hook returns false
|
9
|
+
before_hooks = Plugin.before_enqueue_hooks(klass).collect do |hook|
|
10
|
+
klass.send(hook, *args)
|
11
|
+
end
|
12
|
+
return nil if before_hooks.any? { |result| result == false }
|
13
|
+
|
14
|
+
result = Job.create(queue, klass, *args)
|
15
|
+
return nil if result == "EXISTED"
|
16
|
+
|
17
|
+
Plugin.after_enqueue_hooks(klass).each do |hook|
|
18
|
+
klass.send(hook, *args)
|
19
|
+
end
|
20
|
+
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
3
24
|
def enqueued?(klass, *args)
|
4
25
|
enqueued_in?(queue_from_class(klass), klass, *args)
|
5
26
|
end
|
data/lib/resque_solo/queue.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ResqueSolo
|
2
4
|
class Queue
|
3
5
|
class << self
|
@@ -60,8 +62,12 @@ module ResqueSolo
|
|
60
62
|
end
|
61
63
|
|
62
64
|
def cleanup(queue)
|
63
|
-
|
64
|
-
|
65
|
+
cursor = "0"
|
66
|
+
loop do
|
67
|
+
cursor, keys = redis.scan(cursor, match: "solo:queue:#{queue}:job:*")
|
68
|
+
redis.del(*keys) if keys.any?
|
69
|
+
break if cursor.to_i.zero?
|
70
|
+
end
|
65
71
|
end
|
66
72
|
|
67
73
|
private
|
data/lib/resque_solo/version.rb
CHANGED
data/lib/resque_solo.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_solo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.25.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.25.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '2.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +86,14 @@ dependencies:
|
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '12.0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
96
|
+
version: '12.0'
|
83
97
|
description: Resque plugin to add unique jobs
|
84
98
|
email:
|
85
99
|
- tee@neighborland.com
|
@@ -107,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
121
|
requirements:
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.
|
124
|
+
version: 2.3.0
|
111
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
126
|
requirements:
|
113
127
|
- - ">="
|
@@ -115,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
129
|
version: '0'
|
116
130
|
requirements: []
|
117
131
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.7.7
|
119
133
|
signing_key:
|
120
134
|
specification_version: 4
|
121
135
|
summary: Resque plugin to add unique jobs
|