resque-stagger 0.2.0 → 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 +27 -17
- data/lib/resque/stagger/version.rb +1 -1
- data/lib/resque/stagger.rb +39 -3
- 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
@@ -1,8 +1,6 @@
|
|
1
|
-
# Resque
|
1
|
+
# Resque Stagger
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A Resque plugin for adding a stagger effect to enqueuing jobs.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -14,7 +12,7 @@ gem 'resque-stagger'
|
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
|
-
$ bundle
|
15
|
+
$ bundle install
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
@@ -22,23 +20,35 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
## Development
|
23
|
+
You can use `Resque::Staggered` to enqueue jobs with a stagger effect.
|
28
24
|
|
29
|
-
|
25
|
+
```ruby
|
26
|
+
require "resque/stagger"
|
27
|
+
|
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
|
-
|
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
|
-
|
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.
|
40
51
|
|
41
|
-
##
|
52
|
+
## Contributing
|
42
53
|
|
43
|
-
|
44
|
-
# resque-stagger
|
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
@@ -1,36 +1,72 @@
|
|
1
1
|
require "resque/stagger/version"
|
2
2
|
|
3
|
+
# The Resque module contains the Stagger module.
|
3
4
|
module Resque
|
4
5
|
module Stagger
|
6
|
+
# The Staggered class is used to enqueue jobs with a stagger effect.
|
5
7
|
class Staggered
|
8
|
+
# Initializes the Staggered class with given options.
|
9
|
+
#
|
10
|
+
# @param options [Hash] the options for the stagger effect.
|
11
|
+
# @option options [Time] :start_from starting time for enqueuing jobs.
|
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]
|
6
16
|
def initialize(**options)
|
7
17
|
@options = options
|
8
18
|
end
|
9
19
|
|
20
|
+
# Enqueues the given job with a stagger effect.
|
21
|
+
#
|
22
|
+
# @param klass [Class] the job class to be enqueued.
|
23
|
+
# @param args [Array] the arguments for the job.
|
24
|
+
#
|
25
|
+
# @return [void]
|
10
26
|
def enqueue(klass, *args)
|
11
|
-
|
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
|
12
32
|
end
|
13
33
|
|
14
34
|
private
|
15
35
|
|
36
|
+
# Calculates the time at which the job should be enqueued.
|
37
|
+
#
|
38
|
+
# @return [Time, ActiveSupport::Duration] the enqueue time for the job.
|
16
39
|
def current_enqueue_at
|
17
40
|
return starting_from if per_second.to_i.zero?
|
18
|
-
return @last_enqueued_at = starting_from if @last_enqueued_at.
|
41
|
+
return @last_enqueued_at = starting_from if @last_enqueued_at.nil?
|
19
42
|
|
20
43
|
@enqueued_last_second = @enqueued_last_second.to_i + 1
|
21
|
-
return @last_enqueued_at if @enqueued_last_second < per_second
|
44
|
+
return @last_enqueued_at if @enqueued_last_second < per_second.to_i
|
22
45
|
|
23
46
|
@enqueued_last_second = 0
|
24
47
|
@last_enqueued_at += 1.second
|
25
48
|
end
|
26
49
|
|
50
|
+
# Gets the starting time for enqueuing jobs.
|
51
|
+
#
|
52
|
+
# @return [Time] the starting time for enqueuing jobs.
|
27
53
|
def starting_from
|
28
54
|
@starting_from ||= @options[:start_from] || Time.current
|
29
55
|
end
|
30
56
|
|
57
|
+
# Gets the number of jobs to enqueue per second.
|
58
|
+
#
|
59
|
+
# @return [Integer, nil] the number of jobs to enqueue per second.
|
31
60
|
def per_second
|
32
61
|
@options[:per_second] || nil
|
33
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
|
34
70
|
end
|
35
71
|
end
|
36
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
|