resque-scheduler 4.4.0 → 4.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d023543334a4b91f16d2c055415ee69cb7d1d8a7cf8219c63b7041d6cd83dfe
4
- data.tar.gz: 905a6a650435f19ae58c6cd7cbb6c260485dd23a4335c0cc6a94f285611df783
3
+ metadata.gz: 6cf8e385c64ab6efafcc8f3a499ec2dc8d7be736604e7d4578dd356f1c19d6e9
4
+ data.tar.gz: a564652590bf3c5dc85695cbbb57fb4ca85873de78c94f0580a104ef5d98cf55
5
5
  SHA512:
6
- metadata.gz: 163b20de37de1fba902be2e744cf61b716e04610b391b510f4fe2cbd47aa22299b4a012994a62a928063d749520121cacc58609e10a7b7d1c17126aeb1e5aa49
7
- data.tar.gz: bb1be8accb32a7d682198bdff57b2958526408a1e54093315c322b6a1c69905c6548763057957a563a0fd553c62e5d557b5fad2a5ae6b6f11ba26355ec6270b9
6
+ metadata.gz: 2ab0cea69751963f68055eae115c349a885439a5b33c1c3046a5abd4fc30b676233964d430fa5aeb3eb7960d9339772d41ca31c575156eb4e6583cc66de7497e
7
+ data.tar.gz: f0a4ab726ea640f9df76bbb824078252fb90de9d40c90220611c71069363025933f4a97200c73c13c7c91ff4f02a8c64c735372bbd2e0510e4e5bd021ec081fb
@@ -0,0 +1,12 @@
1
+ version: 2
2
+
3
+ updates:
4
+ - package-ecosystem: "github-actions"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "weekly"
8
+
9
+ - package-ecosystem: "bundler"
10
+ directory: "/"
11
+ schedule:
12
+ interval: "weekly"
@@ -0,0 +1,4 @@
1
+ # Docs for this file can be found here:
2
+ # https://docs.github.com/en/github/administering-a-repository/displaying-a-sponsor-button-in-your-repository
3
+
4
+ github: ["iloveitaly"]
@@ -0,0 +1,59 @@
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ push:
5
+ branches: [ master, '*-stable' ]
6
+ pull_request:
7
+ # The branches below must be a subset of the branches above
8
+ branches: [ master ]
9
+ schedule:
10
+ - cron: '44 16 * * 6'
11
+
12
+ jobs:
13
+ analyze:
14
+ name: Analyze
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ actions: read
18
+ contents: read
19
+ security-events: write
20
+
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ language: [ 'ruby' ]
25
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
26
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
27
+
28
+ steps:
29
+ - name: Checkout repository
30
+ uses: actions/checkout@v4
31
+
32
+ # Initializes the CodeQL tools for scanning.
33
+ - name: Initialize CodeQL
34
+ uses: github/codeql-action/init@v2
35
+ with:
36
+ languages: ${{ matrix.language }}
37
+ # If you wish to specify custom queries, you can do so here or in a config file.
38
+ # By default, queries listed here will override any specified in a config file.
39
+ # Prefix the list here with "+" to use these queries and those in the config file.
40
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
41
+
42
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
43
+ # If this step fails, then you should remove it and run the build manually (see below)
44
+ - name: Autobuild
45
+ uses: github/codeql-action/autobuild@v2
46
+
47
+ # ℹ️ Command-line programs to run using the OS shell.
48
+ # 📚 https://git.io/JvXDl
49
+
50
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
51
+ # and modify them (or add more) to build your code if your project
52
+ # uses a compiled language
53
+
54
+ #- run: |
55
+ # make bootstrap
56
+ # make release
57
+
58
+ - name: Perform CodeQL Analysis
59
+ uses: github/codeql-action/analyze@v2
@@ -0,0 +1,27 @@
1
+ name: Rubocop
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ rubocop:
11
+ name: Rubocop
12
+ runs-on: ${{ matrix.os }}
13
+ strategy:
14
+ matrix:
15
+ os: [ubuntu-latest]
16
+ ruby: [
17
+ 2.7
18
+ ]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ - uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Ruby linter
27
+ run: bundle exec rubocop
@@ -0,0 +1,81 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ test:
11
+ continue-on-error: true
12
+ runs-on: ubuntu-latest
13
+ services:
14
+ redis:
15
+ image: redis
16
+ ports:
17
+ - 6379:6379
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby-version:
22
+ - 2.3
23
+ - 2.4
24
+ - 2.5
25
+ - 2.6
26
+ - 2.7
27
+ - "3.0"
28
+ - 3.1
29
+ - 3.2
30
+ resque-version:
31
+ - "master"
32
+ - "~> 2.4.0"
33
+ - "~> 1.27"
34
+ rufus-scheduler:
35
+ - "3.2"
36
+ - "3.4"
37
+ - "3.5"
38
+ - "3.6"
39
+ redis-version:
40
+ - "~> 4.x"
41
+ - "~> 5.x"
42
+ exclude:
43
+ - ruby-version: head
44
+ rufus-scheduler: 3.2
45
+ - ruby-version: 3.2
46
+ rufus-scheduler: 3.2
47
+
48
+ - ruby-version: 2.3
49
+ resque-version: "~> 1.27"
50
+ rufus-scheduler: 3.4
51
+ - ruby-version: 2.3
52
+ resque-version: "~> 1.27"
53
+ rufus-scheduler: 3.5
54
+ - ruby-version: 2.5
55
+ resque-version: "~> 2.4.0"
56
+ rufus-scheduler: 3.5
57
+ - ruby-version: 2.5
58
+ resque-version: master
59
+ rufus-scheduler: 3.2
60
+
61
+ - ruby-version: 2.3
62
+ redis-version: "~> 5.x"
63
+ - ruby-version: 2.4
64
+ redis-version: "~> 5.x"
65
+
66
+ - resque-version: "~> 1.27"
67
+ redis-version: "~> 5.x"
68
+ env:
69
+ REDIS_VERSION: "${{ matrix.redis-version }}"
70
+ RESQUE: "${{ matrix.resque-version }}"
71
+ RUFUS_SCHEDULER: "${{ matrix.rufus-scheduler }}"
72
+ COVERAGE: 1
73
+
74
+ steps:
75
+ - uses: actions/checkout@v4
76
+ - uses: ruby/setup-ruby@v1
77
+ with:
78
+ ruby-version: "${{ matrix.ruby-version }}"
79
+ bundler-cache: true
80
+ - run: bundle exec rake
81
+ - run: bin/bundle_console_test.sh
data/AUTHORS.md CHANGED
@@ -10,6 +10,7 @@ Resque Scheduler authors
10
10
  - Brian Landau
11
11
  - Brian P O'Rourke
12
12
  - Carlos Antonio da Silva
13
+ - Chris Bisnett
13
14
  - Chris Kampmeier
14
15
  - DJ Hartman
15
16
  - Damon P. Cortesi
@@ -28,8 +29,10 @@ Resque Scheduler authors
28
29
  - Henrik Nyh
29
30
  - Hormoz Kheradmand
30
31
  - Ian Davies
32
+ - Irving Reid
31
33
  - James Le Cuirot
32
34
  - Jarkko Mönkkönen
35
+ - Jimmy Chao
33
36
  - John Crepezzi
34
37
  - John Griffin
35
38
  - Jon Larkowski and Les Hill
@@ -41,6 +44,7 @@ Resque Scheduler authors
41
44
  - Justin Weiss
42
45
  - Les Hill
43
46
  - Luke Rodgers
47
+ - Maksymilian Chwałek
44
48
  - Manuel Meurer
45
49
  - Matt Aimonetti
46
50
  - Matt Simpson
@@ -62,11 +66,13 @@ Resque Scheduler authors
62
66
  - Scott Francis
63
67
  - Sean Stephens
64
68
  - Sebastian Kippe
69
+ - Sharang Dashputre
65
70
  - Spring MC
66
71
  - tbprojects
67
72
  - Tim Liner
68
73
  - Tony Lewis
69
74
  - Tom Crayford
75
+ - Tsu-Shiuan Lin
70
76
  - Vincent Zhu
71
77
  - Vladislav Shub
72
78
  - V Sreekanth
@@ -82,3 +88,5 @@ Resque Scheduler authors
82
88
  - malomalo
83
89
  - sawanoboly
84
90
  - serek
91
+ - iloveitaly
92
+ - treacher
data/CHANGELOG.md CHANGED
@@ -2,6 +2,68 @@
2
2
 
3
3
  **ATTN**: This project uses [semantic versioning](http://semver.org/).
4
4
 
5
+ ## [4.10.2] - 2023-12-15
6
+ ### Fixed
7
+ * Finish fixing CVE-2022-44303, XSS in delayed_schedules by @PatrickTulskie in #783
8
+
9
+ ## [4.10.1] - 2023-12-15
10
+ ### Fixed
11
+ * Fix json dump crasher with JSON 2.7.0+ by @PatrickTulskie in #781
12
+ * Fix for #761, reflected XSS in delayed_schedules.erb by @PatrickTulskie in #780
13
+
14
+ ## [4.10.0] - 2023-08-20
15
+ ### Added
16
+ * Add logfmt option for logging output (#763)
17
+
18
+ ### Fixed
19
+ * Rubocop Fixes (#771)
20
+
21
+ ## [4.9.0] - 2023-05-31
22
+ ### Changed
23
+ - Adding batching to re-queuing for timestamp by @brennen-stripe in #767
24
+ - Use non-deprecated form of Redis.sadd/srem by @irvingreid in #752
25
+ - Prompt for confirmation on 'Clear Delayed Jobs' by @mishina2228 in #754
26
+ - Address some deprecation warnings in the test suite and with srem/lrem pipelined usage by @PatrickTulskie in #770
27
+
28
+ ### Fixed
29
+ - Update CI matrix and fix tests by @mishina2228 in #766
30
+
31
+ ## [4.8.0] - 2023-27-1
32
+ - Replace deprecated Socket.gethostname with Addrinfo.getaddrinfo to fix deprecation warnings (#753)
33
+
34
+ ## [4.7.0] - 2022-10-6
35
+ ### Fixed
36
+ - Fix tests for redis-rb 5.0 (#757)
37
+ - Use Resque::DataStore#reconnect for redis-rb 5.0 compat (#757)
38
+ - Test suite runs `flushall` to prevent flakiness (#757)
39
+
40
+ ## [4.6.0] - 2022-08-04
41
+ ### Changed
42
+ - Remove support for Ruby < 2.3
43
+ - Configuration to use a set of truthy values to enable boolean settings instead of simply existence
44
+ - Add `delay_or_enqueue_at` for delaying existing jobs or creating a new job(#645)
45
+ - Fix deprecated uses of Redis#pipelined
46
+ - Fix reading configuration from environment for boolean values (#735)
47
+ - Unblock rufus-scheduler lock on lower than 3.7 by fixing scheduler shutdown (#736)
48
+ - Removed testing against jruby (resque doesn't test against jruby)
49
+
50
+ ## [4.5.0] - 2021-09-25
51
+ ### Added
52
+ - Support Ruby 3
53
+ - Add optional argument to `remove_schedule` to control reloading of the schedule
54
+
55
+ ### Fixed
56
+ - Fix XSS vulnerability on the `/delayed/search` page
57
+ - Ensure that jobs are directly created for jobs enqueued at `Time.now`
58
+ - Fix queuing to custom job queues in `enqueue_delayed_selection`
59
+ - Ensure `before_enqueue` and `after_enqueue` callbacks are called in all cases of queuing a job
60
+ - Fix redis error when running resque-scheduler without Redis
61
+
62
+ ### Changed
63
+ - Change CI from Travis to GitHub Actions
64
+ - Only allow rufus-scheduler versions lower than 3.7
65
+ - Update vagrant configuration
66
+
5
67
  ## [4.4.0] - 2019-04-11
6
68
  ### Added
7
69
  - Support Resque 2
@@ -14,7 +76,7 @@
14
76
  - Fix setting the `poll_sleep_amount` option
15
77
  - Escape class names in resque-web /delayed URLs
16
78
 
17
- ## Changed
79
+ ### Changed
18
80
  - Addressed redis-namespace deprecation warnings
19
81
  - Ensure `enqueue_in` args are Numeric, catching a common issue passing `ActiveSupport::Duration`
20
82
 
@@ -424,7 +486,8 @@
424
486
  ### Added
425
487
  - Initial release
426
488
 
427
- [Unreleased]: https://github.com/resque/resque-scheduler/compare/v4.4.0...HEAD
489
+ [Unreleased]: https://github.com/resque/resque-scheduler/compare/v4.5.0...HEAD
490
+ [4.5.0]: https://github.com/resque/resque-scheduler/compare/v4.4.0...v4.5.0
428
491
  [4.4.0]: https://github.com/resque/resque-scheduler/compare/v4.3.1...v4.4.0
429
492
  [4.3.1]: https://github.com/resque/resque-scheduler/compare/v4.3.0...v4.3.1
430
493
  [4.3.0]: https://github.com/resque/resque-scheduler/compare/v4.2.1...v4.3.0
data/Gemfile CHANGED
@@ -1,12 +1,29 @@
1
1
  # vim:fileencoding=utf-8
2
2
  source 'https://rubygems.org'
3
3
 
4
- case req = ENV['RESQUE']
5
- when nil
4
+ case resque_version = ENV.fetch('RESQUE', 'master')
6
5
  when 'master'
7
6
  gem 'resque', git: 'https://github.com/resque/resque'
8
7
  else
9
- gem 'resque', req
8
+ gem 'resque', resque_version
10
9
  end
11
10
 
11
+ case rufus_scheduler_version = ENV.fetch('RUFUS_SCHEDULER', '3.6')
12
+ when 'master'
13
+ gem 'rufus-scheduler', git: 'https://github.com/jmettraux/rufus-scheduler'
14
+ else
15
+ gem 'rufus-scheduler', rufus_scheduler_version
16
+ end
17
+
18
+ case redis_version = ENV.fetch('REDIS_VERSION', 'latest')
19
+ when 'master'
20
+ gem 'redis', git: 'https://github.com/redis/redis-rb'
21
+ when 'latest'
22
+ gem 'redis'
23
+ else
24
+ gem 'redis', redis_version
25
+ end
26
+
27
+ gem 'sinatra', '> 2.0'
28
+
12
29
  gemspec
data/README.md CHANGED
@@ -2,10 +2,8 @@ resque-scheduler
2
2
  ================
3
3
 
4
4
 
5
- [![Dependency Status](https://gemnasium.com/badges/github.com/resque/resque-scheduler.svg)](https://gemnasium.com/github.com/resque/resque-scheduler)
6
5
  [![Gem Version](https://badge.fury.io/rb/resque-scheduler.svg)](https://badge.fury.io/rb/resque-scheduler)
7
- [![Build Status](https://travis-ci.org/resque/resque-scheduler.svg?branch=master)](https://travis-ci.org/resque/resque-scheduler)
8
- [![Windows Build Status](https://ci.appveyor.com/api/projects/status/sxvf2086v5j0absb/branch/master?svg=true)](https://ci.appveyor.com/project/resque/resque-scheduler/branch/master)
6
+ [![Ruby specs](https://github.com/resque/resque-scheduler/actions/workflows/ruby.yml/badge.svg)](https://github.com/resque/resque-scheduler/actions)
9
7
  [![Code Climate](https://codeclimate.com/github/resque/resque-scheduler/badges/gpa.svg)](https://codeclimate.com/github/resque/resque-scheduler)
10
8
 
11
9
  ### Description
@@ -141,7 +139,7 @@ requiring `resque` and `resque/scheduler` (default empty).
141
139
  * `RESQUE_SCHEDULER_INTERVAL` - Interval in seconds for checking if a
142
140
  scheduled job must run (coerced with `Kernel#Float()`) (default `5`)
143
141
  * `LOGFILE` - Log file name (default empty, meaning `$stdout`)
144
- * `LOGFORMAT` - Log output format to use (either `'text'` or `'json'`,
142
+ * `LOGFORMAT` - Log output format to use (either `'text'`, `'json'` or `'logfmt'`,
145
143
  default `'text'`)
146
144
  * `PIDFILE` - If non-empty, write process PID to file (default empty)
147
145
  * `QUIET` - Silence most output if non-empty (equivalent to a level of
@@ -160,7 +158,7 @@ following task to wherever tasks are kept, such as
160
158
  ```ruby
161
159
  task 'resque:pool:setup' do
162
160
  Resque::Pool.after_prefork do |job|
163
- Resque.redis._client.reconnect
161
+ Resque.redis.reconnect
164
162
  end
165
163
  end
166
164
  ```
@@ -213,7 +211,7 @@ since the jobs are stored in a redis sorted set (zset). I can't imagine this
213
211
  being an issue for someone since redis is stupidly fast even at log(n), but full
214
212
  disclosure is always best.
215
213
 
216
- #### Removing Delayed jobs
214
+ #### Removing Delayed Jobs
217
215
 
218
216
  If you have the need to cancel a delayed job, you can do like so:
219
217
 
@@ -257,6 +255,49 @@ Resque.enqueue_delayed_selection { |args| args[0]['account_id'] == current_accou
257
255
  Resque.enqueue_delayed_selection { |args| args[0]['user_id'] == current_user.id }
258
256
  ```
259
257
 
258
+ #### Updating Delayed Jobs
259
+
260
+ Previously delayed jobs may be delayed even further into the future like so:
261
+
262
+ ```ruby
263
+ # after you've enqueued a job like:
264
+ Resque.enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
265
+ # delay running the job until two minutes from now
266
+ Resque.delay_or_enqueue_at(2.minutes.from_now, SendNotifications, :user_id => current_user.id)
267
+ ```
268
+
269
+ You don't need to worry if a matching job has already been queued, because if no matching jobs are found a new job is created and enqueued as if you had called `enqueue_at`. This means you don't need any special conditionals to know if a job has already been queued. You simply create the job like so:
270
+
271
+ ```ruby
272
+ Resque.delay_or_enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
273
+ ```
274
+
275
+ If multiple matching jobs are found, all of the matching jobs will be updated to have the same timestamp even if their original timestamps were not the same.
276
+
277
+ ```ruby
278
+ # enqueue multiple jobs with different delay timestamps
279
+ Resque.enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
280
+ Resque.enqueue_at(2.minutes.from_now, SendNotifications, :user_id => current_user.id)
281
+
282
+ # delay running the two jobs until 5 minutes from now
283
+ Resque.delay_or_enqueue_at(5.minutes.from_now, SendNotifications, :user_id => current_user.id)
284
+ ```
285
+
286
+ The most useful case for increasing the delay of an already delayed job is to batch together work based on multiple events. For example, if you wanted to send a notification email to a user when an event triggers but didn't want to send 10 emails if many events happened within a short period, you could use this technique to delay the noficication email until no events have triggered for a period of time. This way you could send 1 email containing the 10 notifications once no events have triggered for 2 minutes. You could implement this like so:
287
+
288
+ ```ruby
289
+ # Send a notification when an event is created.
290
+ # app/models/event.rb
291
+ after_commit on: :create do
292
+ Resque.delay_or_enqueue_in(2.minutes, SendNotifications, :user_id => user.id)
293
+ end
294
+ ```
295
+
296
+ When the first event is created a job will be scheduled to send unsent notifications to the associated user. If another event is created within the 2 minute window, the timer will be reset to 2 minutes. This will continue as long as new events are created for the specific user before the 2 minute timer expires. Once the timer expires and the job is scheduled any new events that are created will schedule a new job and start the process over. By adjusting the window you can tweak the trade-off between sending notification emails quickly after an event happens and sending fewer emails.
297
+
298
+ Read more in the [original PR](https://github.com/resque/resque-scheduler/pull/645)
299
+
300
+
260
301
  ### Scheduled Jobs (Recurring Jobs)
261
302
 
262
303
  Scheduled (or recurring) jobs are logically no different than a standard cron
@@ -306,7 +347,6 @@ If you would like to setup a job that is executed manually you can configure lik
306
347
 
307
348
  ```yaml
308
349
  ImportOrdersManual:
309
- description: 'Import Amazon Orders Manual'
310
350
  custom_job_class: 'AmazonMws::ImportOrdersJob'
311
351
  never: "* * * * *"
312
352
  queue: high
@@ -346,6 +386,38 @@ seconds past the minute).
346
386
  A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
347
387
  for handling the heavy lifting of the actual scheduling engine.
348
388
 
389
+ ##### Queue with parameters
390
+
391
+ It's possible to specify parameters, that must be given by the user when they manually queue the job. To enable this feature add `parameters` key to scheduled job definition.
392
+
393
+ ```yaml
394
+ queue_documents_for_indexing:
395
+ cron: "0 0 * * *"
396
+ class: "QueueDocuments"
397
+ queue: high
398
+ args:
399
+ foo: "bar"
400
+ a: "b"
401
+ parameters:
402
+ foo:
403
+ description: "value of foo"
404
+ default: "baz"
405
+
406
+ description: "This job queues all content for indexing in solr"
407
+ ```
408
+
409
+ One can use following options for each parameter:
410
+ * description - tooltip to be shown next to the parameter input
411
+ * default - prefilled value in the parameter input
412
+
413
+ **NOTE**: When sheduling the job, parameters are merged into job args. Assuming the example above and default parametr value, the job will be run with the following args:
414
+
415
+ ```ruby
416
+ {"foo"=>"baz", "a"=>"b"}
417
+ ```
418
+
419
+ **NOTE**: If user leaves the parameter value empty, it'll be sent as empty string.
420
+
349
421
  #### Dynamic schedules
350
422
 
351
423
  Dynamic schedules are programmatically set on a running `resque-scheduler`.
@@ -407,18 +479,17 @@ Resque.set_schedule(name, config)
407
479
 
408
480
  #### Time zones
409
481
 
410
- Note that if you use the cron syntax, this will be interpreted as in the server time zone
411
- rather than the `config.time_zone` specified in Rails.
412
-
482
+ If you use the cron syntax, by default it is interpreted in the server time zone.
413
483
  You can explicitly specify the time zone that rufus-scheduler will use:
414
-
415
484
  ```yaml
416
485
  cron: "30 6 * * 1 Europe/Stockholm"
417
486
  ```
418
487
 
419
- Also note that `config.time_zone` in Rails allows for a shorthand (e.g. "Stockholm")
420
- that rufus-scheduler does not accept. If you write code to set the scheduler time zone
421
- from the `config.time_zone` value, make sure it's the right format, e.g. with:
488
+ ##### Rails
489
+ In Rails, `config.time_zone` will be used to determine the time zone for `resque-scheduler`.
490
+
491
+ Note that `config.time_zone` allows for a shorthand (e.g. "Stockholm")
492
+ that rufus-scheduler does not accept, so make sure it's the right format, e.g. with:
422
493
 
423
494
  ```ruby
424
495
  ActiveSupport::TimeZone.find_tzinfo(Rails.configuration.time_zone).name
@@ -575,7 +646,7 @@ Now make sure you're passing that file to resque-web like so:
575
646
 
576
647
  ### Running in the background
577
648
 
578
- (Only supported with ruby >= 1.9). There are scenarios where it's helpful for
649
+ There are scenarios where it's helpful for
579
650
  the resque worker to run itself in the background (usually in combination with
580
651
  PIDFILE). Use the BACKGROUND option so that rake will return as soon as the
581
652
  worker is started.
@@ -592,7 +663,7 @@ are toggled by environment variables:
592
663
  - `QUIET` will stop logging anything. Completely silent.
593
664
  - `VERBOSE` opposite of 'QUIET'; will log even debug information
594
665
  - `LOGFILE` specifies the file to write logs to. (default standard output)
595
- - `LOGFORMAT` specifies either "text" or "json" output format
666
+ - `LOGFORMAT` specifies either "text", "json" or "logfmt" output format
596
667
  (default "text")
597
668
 
598
669
  All of these variables are optional and will be given the following default
@@ -641,7 +712,7 @@ that happens on Travis CI and Appveyor:
641
712
  bundle install
642
713
 
643
714
  # Make sure tests are green before you change stuff
644
- bundle exec rake
715
+ bundle exec rubocop && bundle exec rake
645
716
  # Change stuff
646
717
  # Repeat
647
718
  ```
data/Rakefile CHANGED
@@ -1,13 +1,9 @@
1
1
  # vim:fileencoding=utf-8
2
2
  require 'bundler/gem_tasks'
3
3
  require 'rake/testtask'
4
- require 'rubocop/rake_task'
5
4
  require 'yard'
6
5
 
7
- task default: [:rubocop, :test] unless RUBY_PLATFORM =~ /java/
8
- task default: [:test] if RUBY_PLATFORM =~ /java/
9
-
10
- RuboCop::RakeTask.new
6
+ task default: :test
11
7
 
12
8
  Rake::TestTask.new do |t|
13
9
  t.libs << 'test'
@@ -16,6 +12,7 @@ Rake::TestTask.new do |t|
16
12
  o << "--seed #{ENV['SEED']} " if ENV['SEED']
17
13
  o << '--verbose ' if ENV['VERBOSE']
18
14
  end
15
+ t.warning = false
19
16
  end
20
17
 
21
18
  YARD::Rake::YardocTask.new
@@ -8,13 +8,18 @@ module Resque
8
8
  yield self
9
9
  end
10
10
 
11
+ attr_writer :environment
12
+ def environment
13
+ @environment ||= ENV
14
+ end
15
+
11
16
  # Used in `#load_schedule_job`
12
17
  attr_writer :env
13
18
 
14
19
  def env
15
20
  return @env if @env
16
21
  @env ||= Rails.env if defined?(Rails) && Rails.respond_to?(:env)
17
- @env ||= ENV['RAILS_ENV']
22
+ @env ||= environment['RAILS_ENV']
18
23
  @env
19
24
  end
20
25
 
@@ -22,42 +27,48 @@ module Resque
22
27
  attr_writer :verbose
23
28
 
24
29
  def verbose
25
- @verbose ||= !!ENV['VERBOSE']
30
+ @verbose ||= to_bool(environment['VERBOSE'])
26
31
  end
27
32
 
28
33
  # If set, produces no output
29
34
  attr_writer :quiet
30
35
 
31
36
  def quiet
32
- @quiet ||= !!ENV['QUIET']
37
+ @quiet ||= to_bool(environment['QUIET'])
33
38
  end
34
39
 
35
40
  # If set, will write messages to the file
36
41
  attr_writer :logfile
37
42
 
38
43
  def logfile
39
- @logfile ||= ENV['LOGFILE']
44
+ @logfile ||= environment['LOGFILE']
40
45
  end
41
46
 
42
- # Sets whether to log in 'text' or 'json'
47
+ # Sets whether to log in 'text', 'json' or 'logfmt'
43
48
  attr_writer :logformat
44
49
 
45
50
  def logformat
46
- @logformat ||= ENV['LOGFORMAT']
51
+ @logformat ||= environment['LOGFORMAT']
47
52
  end
48
53
 
49
54
  # If set, will try to update the schedule in the loop
50
55
  attr_writer :dynamic
51
56
 
52
57
  def dynamic
53
- @dynamic ||= !!ENV['DYNAMIC_SCHEDULE']
58
+ @dynamic ||= to_bool(environment['DYNAMIC_SCHEDULE'])
54
59
  end
55
60
 
56
61
  # If set, will append the app name to procline
57
62
  attr_writer :app_name
58
63
 
59
64
  def app_name
60
- @app_name ||= ENV['APP_NAME']
65
+ @app_name ||= environment['APP_NAME']
66
+ end
67
+
68
+ def delayed_requeue_batch_size
69
+ @delayed_requeue_batch_size ||= \
70
+ ENV['DELAYED_REQUEUE_BATCH_SIZE'].to_i if environment['DELAYED_REQUEUE_BATCH_SIZE']
71
+ @delayed_requeue_batch_size ||= 100
61
72
  end
62
73
 
63
74
  # Amount of time in seconds to sleep between polls of the delayed
@@ -66,7 +77,25 @@ module Resque
66
77
 
67
78
  def poll_sleep_amount
68
79
  @poll_sleep_amount ||=
69
- Float(ENV.fetch('RESQUE_SCHEDULER_INTERVAL', '5'))
80
+ Float(environment.fetch('RESQUE_SCHEDULER_INTERVAL', '5'))
81
+ end
82
+
83
+ private
84
+
85
+ # Copied from https://github.com/rails/rails/blob/main/activemodel/lib/active_model/type/boolean.rb#L17
86
+ TRUE_VALUES = [
87
+ true, 1,
88
+ '1', :'1',
89
+ 't', :t,
90
+ 'T', :T,
91
+ 'true', :true,
92
+ 'TRUE', :TRUE,
93
+ 'on', :on,
94
+ 'ON', :ON
95
+ ].to_set.freeze
96
+
97
+ def to_bool(value)
98
+ TRUE_VALUES.include?(value)
70
99
  end
71
100
  end
72
101
  end