sidekiq-scheduler 2.1.1 → 2.1.2
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 +4 -4
- data/README.md +32 -0
- data/lib/sidekiq-scheduler/manager.rb +1 -1
- data/lib/sidekiq-scheduler/version.rb +1 -1
- data/lib/sidekiq/scheduler.rb +34 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae34c739c46b8fbf1ff40509dbdd8cca94f736c5
|
4
|
+
data.tar.gz: 4bfb4cc75fc85ee2cd5a3fee274820f14241f8eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a922a153b0c8c6fbfc894557f5f90564a0120c66205e6ffffd9f520aa9fd1a4f4e40e4c677c20830e5224f1c9767daf757c1adcb8ed1dcf2ebcb21d0e57bf749
|
7
|
+
data.tar.gz: 40ad60c1df2b902a748d297a89d5571839f074e7407efc3f44d28a7f1cc240049d1e9cdd7e4ce40bedc485766aec5dfd799596821a3a48ffa812fb868ad9095c
|
data/README.md
CHANGED
@@ -117,10 +117,42 @@ The schedule is configured through the `:schedule` config entry in the sidekiq c
|
|
117
117
|
args: ['*.pdf']
|
118
118
|
description: "This job queues pdf content for indexing in solr"
|
119
119
|
|
120
|
+
# Enable the `metadata` argument which will pass a Hash containing the schedule metadata
|
121
|
+
# as the last argument of the `perform` method. `false` by default.
|
122
|
+
include_metadata: true
|
123
|
+
|
120
124
|
# Enable / disable a job. All jobs are enabled by default.
|
121
125
|
enabled: true
|
122
126
|
```
|
123
127
|
|
128
|
+
### Schedule metadata
|
129
|
+
You can configure Sidekiq-scheduler to pass an argument with metadata about the scheduling process
|
130
|
+
to the worker's `perform` method.
|
131
|
+
|
132
|
+
In the configuration file add the following on each worker class entry:
|
133
|
+
|
134
|
+
```yaml
|
135
|
+
|
136
|
+
SampleWorker:
|
137
|
+
include_metadata: true
|
138
|
+
```
|
139
|
+
|
140
|
+
On your `perform` method, expect an additional argument:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
def perform(args, ..., metadata)
|
144
|
+
# Do something with the metadata
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
The `metadata` hash contains the following keys:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
metadata.keys =>
|
152
|
+
[
|
153
|
+
:scheduled_at # The epoch when the job was scheduled to run
|
154
|
+
]
|
155
|
+
```
|
124
156
|
|
125
157
|
## Schedule types
|
126
158
|
|
@@ -18,7 +18,7 @@ module SidekiqScheduler
|
|
18
18
|
Sidekiq::Scheduler.enabled = options[:enabled]
|
19
19
|
Sidekiq::Scheduler.dynamic = options[:dynamic]
|
20
20
|
Sidekiq::Scheduler.listened_queues_only = options[:listened_queues_only]
|
21
|
-
Sidekiq.schedule = options[:schedule]
|
21
|
+
Sidekiq.schedule = options[:schedule] if Sidekiq::Scheduler.enabled
|
22
22
|
end
|
23
23
|
|
24
24
|
def stop
|
data/lib/sidekiq/scheduler.rb
CHANGED
@@ -124,7 +124,7 @@ module Sidekiq
|
|
124
124
|
if registered
|
125
125
|
logger.info "queueing #{config['class']} (#{job_name})"
|
126
126
|
|
127
|
-
handle_errors { enqueue_job(config) }
|
127
|
+
handle_errors { enqueue_job(config, time) }
|
128
128
|
|
129
129
|
remove_elder_job_instances(job_name)
|
130
130
|
else
|
@@ -157,13 +157,20 @@ module Sidekiq
|
|
157
157
|
end
|
158
158
|
|
159
159
|
# Enqueue a job based on a config hash
|
160
|
-
|
160
|
+
#
|
161
|
+
# @param job_config [Hash] the job configuration
|
162
|
+
# @param time [Time] time the job is enqueued
|
163
|
+
def enqueue_job(job_config, time=Time.now)
|
161
164
|
config = prepare_arguments(job_config.dup)
|
162
165
|
|
166
|
+
if config.delete('include_metadata')
|
167
|
+
config['args'] = arguments_with_metadata(config['args'], scheduled_at: time.to_f)
|
168
|
+
end
|
169
|
+
|
163
170
|
if active_job_enqueue?(config['class'])
|
164
|
-
|
171
|
+
enqueue_with_active_job(config)
|
165
172
|
else
|
166
|
-
|
173
|
+
enqueue_with_sidekiq(config)
|
167
174
|
end
|
168
175
|
end
|
169
176
|
|
@@ -222,11 +229,12 @@ module Sidekiq
|
|
222
229
|
end
|
223
230
|
end
|
224
231
|
|
225
|
-
def
|
226
|
-
|
232
|
+
def enqueue_with_active_job(config)
|
233
|
+
# TODO Does ActiveJob really need to get the config data in the `enqueue` call?
|
234
|
+
initialize_active_job(config['class'], config['args']).enqueue(sanitize_job_config(config))
|
227
235
|
end
|
228
236
|
|
229
|
-
def
|
237
|
+
def enqueue_with_sidekiq(config)
|
230
238
|
Sidekiq::Client.push(sanitize_job_config(config))
|
231
239
|
end
|
232
240
|
|
@@ -385,6 +393,25 @@ module Sidekiq
|
|
385
393
|
Sidekiq.redis { |r| r.hset(schedules_state_key, name, JSON.generate(state)) }
|
386
394
|
end
|
387
395
|
|
396
|
+
# Adds a Hash with schedule metadata as the last argument to call the worker.
|
397
|
+
# It currently returns the schedule time as a Float number representing the milisencods
|
398
|
+
# since epoch.
|
399
|
+
#
|
400
|
+
# @example with hash argument
|
401
|
+
# arguments_with_metadata({value: 1}, scheduled_at: Time.now)
|
402
|
+
# #=> [{value: 1}, {scheduled_at: <miliseconds since epoch>}]
|
403
|
+
#
|
404
|
+
# @param args [Array|Hash]
|
405
|
+
# @param metadata [Hash]
|
406
|
+
# @return [Array] arguments with added metadata
|
407
|
+
def arguments_with_metadata(args, metadata)
|
408
|
+
if args.is_a? Array
|
409
|
+
[*args, metadata]
|
410
|
+
else
|
411
|
+
[args, metadata]
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
388
415
|
end
|
389
416
|
end
|
390
417
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morton Jonuschat
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-02-
|
12
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|