resque-stagger 0.2.1 → 0.3.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 +5 -5
- data/.gitignore +1 -0
- data/.idea/resque-stagger.iml +22 -2
- data/LICENSE +21 -0
- data/README.md +17 -13
- data/lib/resque/stagger/version.rb +1 -1
- data/lib/resque/stagger.rb +18 -2
- data/resque-stagger.gemspec +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 53ae0e00d2158526b7b4fe759c68de683ef0d3c7d1f93db8723e36c470f92e21
|
4
|
+
data.tar.gz: 02c043493d56f334c2848916a411383ab6bf1cad5e4b66c7cab75386f7cf45a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15ecf8e1b4d1e84d0a5cd796317e3e1220b7441ff63e27ec37f5a14c486cc8ec676b2591177dc2c50f08eacbb1202f95b598c6d21b9e87d19f8319d936e656b2
|
7
|
+
data.tar.gz: 728cd6efa8a97aa900e280fa2f939705bf711046fc1f0bef6a7157def42da8e6a6c46940573ad99280be240d0ec73f01951b7a6e67fa67db223268f2ed71bc2b
|
data/.gitignore
CHANGED
data/.idea/resque-stagger.iml
CHANGED
@@ -9,8 +9,28 @@
|
|
9
9
|
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
10
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
11
|
</content>
|
12
|
-
<orderEntry type="
|
12
|
+
<orderEntry type="jdk" jdkName="Remote: ruby-2.3.8-p459" jdkType="RUBY_SDK" />
|
13
13
|
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.0.2, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="et-orbi (v1.2.7, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="fugit (v1.8.0, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="mono_logger (v1.1.1, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.15.0, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="mustermann (v2.0.2, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="raabro (v1.4.0, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rack (v2.2.4, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="rack-protection (v2.2.4, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="redis (v4.4.0, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="redis-namespace (v1.6.0, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="resque (v2.0.0, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="resque-scheduler (v4.4.0, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby2_keywords (v0.0.5, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="rufus-scheduler (v3.8.2, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="sinatra (v2.2.4, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="tilt (v2.0.11, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.10, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="vegas (v0.1.11, Remote: ruby-2.3.8-p459) [gem]" level="application" />
|
15
35
|
</component>
|
16
36
|
</module>
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Parikshit Singh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -25,26 +25,30 @@ You can use `Resque::Staggered` to enqueue jobs with a stagger effect.
|
|
25
25
|
```ruby
|
26
26
|
require "resque/stagger"
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
staggered = Resque::Staggered.new(per_second: 2, start_from: Time.now + 5.seconds, queue: :low)
|
29
|
+
|
30
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds
|
31
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds
|
32
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 1.second
|
33
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 1.second
|
34
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 2.second
|
35
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 2.second
|
36
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 3.second
|
37
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 3.second
|
38
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 4.second
|
39
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 4.second
|
40
|
+
staggered.enqueue(MyJob, "arg1", "arg2") # This will be enqueued at Time.now + 5.seconds + 5.second
|
30
41
|
|
31
42
|
```
|
32
43
|
|
33
|
-
The Staggered class takes
|
44
|
+
The Staggered class takes three optional parameters: :per_second, :start_from and :queue.
|
34
45
|
|
35
46
|
> **:per_second** is the number of jobs to enqueue per second. The default value is nil, which means no limit on the number of jobs to enqueue per second.
|
36
47
|
|
37
48
|
> **:start_from** is the starting time for enqueuing jobs. The default value is Time.current.
|
38
49
|
|
39
|
-
|
40
|
-
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/resque-stagger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
42
|
-
|
43
|
-
## License
|
50
|
+
> **:queue** is the queue you want to enqueue the staggered job at (when its time comes). Default value of queue is `nil` which is based on the assumption that the job class will be defining this queue explicitly and there is no need to give the queue name separately.
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
## Code of Conduct
|
48
|
-
|
49
|
-
Everyone interacting in the Resque Stagger project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/resque-stagger/blob/master/CODE_OF_CONDUCT.md).
|
52
|
+
## Contributing
|
50
53
|
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/parikshit223933/resque-stagger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
data/lib/resque/stagger.rb
CHANGED
@@ -10,6 +10,9 @@ module Resque
|
|
10
10
|
# @param options [Hash] the options for the stagger effect.
|
11
11
|
# @option options [Time] :start_from starting time for enqueuing jobs.
|
12
12
|
# @option options [Integer] :per_second number of jobs to enqueue per second.
|
13
|
+
# @option options [String] :queue name of the queue to enqueue jobs in.
|
14
|
+
#
|
15
|
+
# @return [void]
|
13
16
|
def initialize(**options)
|
14
17
|
@options = options
|
15
18
|
end
|
@@ -18,15 +21,21 @@ module Resque
|
|
18
21
|
#
|
19
22
|
# @param klass [Class] the job class to be enqueued.
|
20
23
|
# @param args [Array] the arguments for the job.
|
24
|
+
#
|
25
|
+
# @return [void]
|
21
26
|
def enqueue(klass, *args)
|
22
|
-
|
27
|
+
if queue.present?
|
28
|
+
::Resque.enqueue_at_with_queue(queue, current_enqueue_at, klass, *args)
|
29
|
+
else
|
30
|
+
::Resque.enqueue_at(current_enqueue_at, klass, *args)
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
34
|
private
|
26
35
|
|
27
36
|
# Calculates the time at which the job should be enqueued.
|
28
37
|
#
|
29
|
-
# @return [Time] the enqueue time for the job.
|
38
|
+
# @return [Time, ActiveSupport::Duration] the enqueue time for the job.
|
30
39
|
def current_enqueue_at
|
31
40
|
return starting_from if per_second.to_i.zero?
|
32
41
|
return @last_enqueued_at = starting_from if @last_enqueued_at.nil?
|
@@ -51,6 +60,13 @@ module Resque
|
|
51
60
|
def per_second
|
52
61
|
@options[:per_second] || nil
|
53
62
|
end
|
63
|
+
|
64
|
+
# Returns the name of the queue to enqueue jobs in.
|
65
|
+
#
|
66
|
+
# @return [String, nil] the name of the queue, or nil if not specified.
|
67
|
+
def queue
|
68
|
+
@options[:queue] || nil
|
69
|
+
end
|
54
70
|
end
|
55
71
|
end
|
56
72
|
end
|
data/resque-stagger.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/parikshit223933/resque-stagger"
|
20
|
-
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-stagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parikshit Singh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- ".travis.yml"
|
98
98
|
- CODE_OF_CONDUCT.md
|
99
99
|
- Gemfile
|
100
|
+
- LICENSE
|
100
101
|
- LICENSE.txt
|
101
102
|
- README.md
|
102
103
|
- Rakefile
|
@@ -112,7 +113,6 @@ metadata:
|
|
112
113
|
allowed_push_host: https://rubygems.org
|
113
114
|
homepage_uri: https://github.com/parikshit223933/resque-stagger
|
114
115
|
source_code_uri: https://github.com/parikshit223933/resque-stagger
|
115
|
-
changelog_uri: 'TODO: Put your gem''s CHANGELOG.md URL here.'
|
116
116
|
post_install_message:
|
117
117
|
rdoc_options: []
|
118
118
|
require_paths:
|
@@ -128,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
|
132
|
-
rubygems_version: 2.5.1
|
131
|
+
rubygems_version: 3.0.3.1
|
133
132
|
signing_key:
|
134
133
|
specification_version: 4
|
135
134
|
summary: This will stagger your resque jobs over a configurable duration rather then
|