resque-stagger 0.3.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +26 -0
- data/README.md +34 -28
- data/bin/console +1 -1
- data/lib/resque/{stagger → staggered}/version.rb +1 -1
- data/lib/resque/staggered.rb +80 -0
- data/lib/resque-staggered.rb +2 -0
- data/resque-stagger.gemspec +3 -2
- metadata +21 -10
- data/.idea/.gitignore +0 -8
- data/.idea/misc.xml +0 -4
- data/.idea/modules.xml +0 -8
- data/.idea/resque-stagger.iml +0 -36
- data/.idea/vcs.xml +0 -6
- data/LICENSE +0 -21
- data/lib/resque/stagger.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 159e7ada89f6f00107b1445850c12eedfa73ad6dd5e45cbc806e286467b5a964
|
4
|
+
data.tar.gz: 8f0bb3379c3f431729907b1c652b62fbb6ed55319bef75569b683d7b87d55e27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50e12311484c9454639c035ef8ac8165ace0ccec1841454ea47305245083563678361ffd8e94c25ef5cca1f31f46c2d39328b0c2cc2db8b5946d27670eb3de07
|
7
|
+
data.tar.gz: ae8b9148e21084f60462a8e668900d205b58dd02c9624e16025c9805e62560b84cd72c6a5ea17db01e51f66bd11c627bdc9daa027a84e4d1fe849c49695cf225
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## 0.2.1
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Staggering functionality
|
6
|
+
|
7
|
+
## 0.3.0
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
* Queue name can be given on runtime
|
12
|
+
|
13
|
+
## 1.0.2
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
* Improper way of prepending module
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
* Functionality to enqueue single job in a non-unit time range.
|
22
|
+
For example, earlier "n" jobs could have been scheduled per unit time,
|
23
|
+
i.e. in 1 second, but now it can be done both ways i.e. 1 job can be
|
24
|
+
scheduled to be enqueued per 5 seconds as well as 5 jobs can be
|
25
|
+
scheduled to be enqueued in 1 second.
|
26
|
+
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
# Resque
|
1
|
+
# Resque-Stagger
|
2
2
|
|
3
|
-
|
3
|
+
resque-stagger is a simple Ruby gem that allows you to stagger the enqueuing of jobs
|
4
|
+
in [Resque](https://github.com/resque/resque).
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -12,43 +13,48 @@ gem 'resque-stagger'
|
|
12
13
|
|
13
14
|
And then execute:
|
14
15
|
|
15
|
-
|
16
|
+
```shell
|
17
|
+
bundle install
|
18
|
+
```
|
16
19
|
|
17
20
|
Or install it yourself as:
|
18
21
|
|
19
|
-
|
22
|
+
```shell
|
23
|
+
gem install resque-stagger
|
24
|
+
```
|
20
25
|
|
21
26
|
## Usage
|
22
27
|
|
23
|
-
You can use `Resque::Staggered` to enqueue jobs with a stagger effect.
|
24
|
-
|
25
28
|
```ruby
|
26
|
-
require
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
41
|
-
|
29
|
+
require 'resque/staggered'
|
30
|
+
|
31
|
+
# Set up a new staggered queue
|
32
|
+
queue = Resque::Staggered.new(
|
33
|
+
start_from: Time.now + 60, # Start queuing jobs 60 seconds from now
|
34
|
+
number_of_jobs: 10, # Enqueue 10 jobs per time interval
|
35
|
+
unit_time_in_seconds: 300, # Interval of 5 minutes between each set of jobs
|
36
|
+
queue: 'low' # Enqueue jobs in the 'low' queue
|
37
|
+
)
|
38
|
+
|
39
|
+
# Enqueue a job with arguments
|
40
|
+
queue.enqueue(MyJobClass, arg1, arg2, arg3)
|
42
41
|
```
|
43
42
|
|
44
|
-
The
|
43
|
+
- The code sets up a new staggered queue using Resque::Staggered and then enqueues a job with arguments using the
|
44
|
+
enqueue method of the staggered queue.
|
45
45
|
|
46
|
-
|
46
|
+
- Based on the options passed to the Resque::Staggered constructor, the staggered queue will enqueue 10 jobs every 5
|
47
|
+
minutes (300 seconds) starting 60 seconds from the current time, and enqueue the jobs in the "low" queue.
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
- So, if this code is run at 12:00 PM, the first set of 10 jobs will be enqueued at 12:01 PM (60 seconds later), the
|
50
|
+
second set of 10 jobs will be enqueued at 12:06 PM (5 minutes later), the third set of 10 jobs will be enqueued at 12:
|
51
|
+
11 PM (5 minutes later), and so on.
|
51
52
|
|
52
53
|
## Contributing
|
53
54
|
|
54
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/parikshit223933/resque-stagger.
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/parikshit223933/resque-stagger.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of
|
60
|
+
the [MIT License](https://github.com/parikshit223933/resque-stagger/blob/master/LICENSE.txt).
|
data/bin/console
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "resque/staggered/version"
|
2
|
+
|
3
|
+
module Resque
|
4
|
+
class Staggered
|
5
|
+
# Initializes a new Staggered object.
|
6
|
+
#
|
7
|
+
# @param options [Hash] The options to create the Staggered object with.
|
8
|
+
# @option options [Time] :start_from The time to start enqueueing jobs from (defaults to Time.current).
|
9
|
+
# @option options [Integer] :number_of_jobs The number of jobs to enqueue per unit time.
|
10
|
+
# @option options [Integer] :unit_time_in_seconds The time interval between each set of jobs.
|
11
|
+
# @option options [String] :queue The name of the queue to enqueue the jobs in (optional).
|
12
|
+
#
|
13
|
+
# @return [Staggered] A new instance of the Staggered class.
|
14
|
+
def initialize(**options)
|
15
|
+
@options = options
|
16
|
+
end
|
17
|
+
|
18
|
+
# Enqueues a job with the given arguments at a staggered time.
|
19
|
+
#
|
20
|
+
# @param klass [Object] The job class to enqueue.
|
21
|
+
# @param args [Array] The arguments to pass to the job.
|
22
|
+
#
|
23
|
+
# @return [void]
|
24
|
+
def enqueue(klass, *args)
|
25
|
+
if queue.present?
|
26
|
+
::Resque.enqueue_at_with_queue(queue, current_enqueue_at, klass, *args)
|
27
|
+
else
|
28
|
+
::Resque.enqueue_at(current_enqueue_at, klass, *args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Calculates the staggered time for the next job and returns it.
|
35
|
+
#
|
36
|
+
# @return [Time] The staggered time for the next job.
|
37
|
+
def current_enqueue_at
|
38
|
+
if number_of_jobs > @enqueues_in_last_unit_time.to_i
|
39
|
+
@enqueues_in_last_unit_time = @enqueues_in_last_unit_time.to_i + 1
|
40
|
+
if @unit_time_timestamp.nil?
|
41
|
+
return @unit_time_timestamp = starting_from
|
42
|
+
else
|
43
|
+
return @unit_time_timestamp
|
44
|
+
end
|
45
|
+
else
|
46
|
+
@enqueues_in_last_unit_time = 0
|
47
|
+
@unit_time_timestamp = @unit_time_timestamp + unit_time_in_seconds.second
|
48
|
+
current_enqueue_at
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns the time to start from.
|
53
|
+
#
|
54
|
+
# @return [Time] The time to start from.
|
55
|
+
def starting_from
|
56
|
+
@starting_from ||= @options[:start_from] || Time.current
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the number of jobs to enqueue.
|
60
|
+
#
|
61
|
+
# @return [Integer] The number of jobs to enqueue.
|
62
|
+
def number_of_jobs
|
63
|
+
@options[:number_of_jobs] || nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns the time interval between each set of jobs.
|
67
|
+
#
|
68
|
+
# @return [Integer] The time interval between each set of jobs.
|
69
|
+
def unit_time_in_seconds
|
70
|
+
@options[:unit_time_in_seconds] || nil
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the name of the queue to enqueue the jobs in.
|
74
|
+
#
|
75
|
+
# @return [String] The name of the queue to enqueue the jobs in.
|
76
|
+
def queue
|
77
|
+
@options[:queue] || nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/resque-stagger.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "resque/
|
3
|
+
require "resque/staggered/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "resque-stagger"
|
@@ -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
|
-
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/parikshit223933/resque-stagger/blob/master/CHANGELOG.md"
|
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.
|
@@ -33,5 +33,6 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
34
|
|
35
35
|
spec.add_runtime_dependency 'resque', '>= 1.25'
|
36
|
+
spec.add_runtime_dependency 'activesupport', '>= 5.1.7'
|
36
37
|
spec.add_runtime_dependency 'resque-scheduler', '>= 4.4.0'
|
37
38
|
end
|
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.3
|
4
|
+
version: 1.0.3
|
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-03-
|
11
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.25'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.1.7
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.1.7
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: resque-scheduler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,23 +102,19 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
91
|
-
- ".idea/.gitignore"
|
92
|
-
- ".idea/misc.xml"
|
93
|
-
- ".idea/modules.xml"
|
94
|
-
- ".idea/resque-stagger.iml"
|
95
|
-
- ".idea/vcs.xml"
|
96
105
|
- ".rspec"
|
97
106
|
- ".travis.yml"
|
107
|
+
- CHANGELOG.md
|
98
108
|
- CODE_OF_CONDUCT.md
|
99
109
|
- Gemfile
|
100
|
-
- LICENSE
|
101
110
|
- LICENSE.txt
|
102
111
|
- README.md
|
103
112
|
- Rakefile
|
104
113
|
- bin/console
|
105
114
|
- bin/setup
|
106
|
-
- lib/resque
|
107
|
-
- lib/resque/
|
115
|
+
- lib/resque-staggered.rb
|
116
|
+
- lib/resque/staggered.rb
|
117
|
+
- lib/resque/staggered/version.rb
|
108
118
|
- resque-stagger.gemspec
|
109
119
|
homepage: https://github.com/parikshit223933/resque-stagger
|
110
120
|
licenses:
|
@@ -113,6 +123,7 @@ metadata:
|
|
113
123
|
allowed_push_host: https://rubygems.org
|
114
124
|
homepage_uri: https://github.com/parikshit223933/resque-stagger
|
115
125
|
source_code_uri: https://github.com/parikshit223933/resque-stagger
|
126
|
+
changelog_uri: https://github.com/parikshit223933/resque-stagger/blob/master/CHANGELOG.md
|
116
127
|
post_install_message:
|
117
128
|
rdoc_options: []
|
118
129
|
require_paths:
|
data/.idea/.gitignore
DELETED
data/.idea/misc.xml
DELETED
data/.idea/modules.xml
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project version="4">
|
3
|
-
<component name="ProjectModuleManager">
|
4
|
-
<modules>
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/resque-stagger.iml" filepath="$PROJECT_DIR$/.idea/resque-stagger.iml" />
|
6
|
-
</modules>
|
7
|
-
</component>
|
8
|
-
</project>
|
data/.idea/resque-stagger.iml
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="ModuleRunConfigurationManager">
|
4
|
-
<shared />
|
5
|
-
</component>
|
6
|
-
<component name="NewModuleRootManager">
|
7
|
-
<content url="file://$MODULE_DIR$">
|
8
|
-
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
-
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
-
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
-
</content>
|
12
|
-
<orderEntry type="jdk" jdkName="Remote: ruby-2.3.8-p459" jdkType="RUBY_SDK" />
|
13
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
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" />
|
35
|
-
</component>
|
36
|
-
</module>
|
data/.idea/vcs.xml
DELETED
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
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/lib/resque/stagger.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require "resque/stagger/version"
|
2
|
-
|
3
|
-
# The Resque module contains the Stagger module.
|
4
|
-
module Resque
|
5
|
-
module Stagger
|
6
|
-
# The Staggered class is used to enqueue jobs with a stagger effect.
|
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]
|
16
|
-
def initialize(**options)
|
17
|
-
@options = options
|
18
|
-
end
|
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]
|
26
|
-
def enqueue(klass, *args)
|
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
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
# Calculates the time at which the job should be enqueued.
|
37
|
-
#
|
38
|
-
# @return [Time, ActiveSupport::Duration] the enqueue time for the job.
|
39
|
-
def current_enqueue_at
|
40
|
-
return starting_from if per_second.to_i.zero?
|
41
|
-
return @last_enqueued_at = starting_from if @last_enqueued_at.nil?
|
42
|
-
|
43
|
-
@enqueued_last_second = @enqueued_last_second.to_i + 1
|
44
|
-
return @last_enqueued_at if @enqueued_last_second < per_second.to_i
|
45
|
-
|
46
|
-
@enqueued_last_second = 0
|
47
|
-
@last_enqueued_at += 1.second
|
48
|
-
end
|
49
|
-
|
50
|
-
# Gets the starting time for enqueuing jobs.
|
51
|
-
#
|
52
|
-
# @return [Time] the starting time for enqueuing jobs.
|
53
|
-
def starting_from
|
54
|
-
@starting_from ||= @options[:start_from] || Time.current
|
55
|
-
end
|
56
|
-
|
57
|
-
# Gets the number of jobs to enqueue per second.
|
58
|
-
#
|
59
|
-
# @return [Integer, nil] the number of jobs to enqueue per second.
|
60
|
-
def per_second
|
61
|
-
@options[:per_second] || nil
|
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
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
Resque.prepend(Resque::Stagger)
|