Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: resque/resque-scheduler
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e1c9334a236b83e4bbd5af6bfa24176bd1ee6183
Choose a base ref
..
head repository: resque/resque-scheduler
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b0ab10614b6d7ada2b69bdb39b18d690c9990b3e
Choose a head ref
59 changes: 59 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "CodeQL"

on:
push:
branches: [ master, '*-stable' ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '44 16 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'ruby' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ jobs:
]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
75 changes: 69 additions & 6 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ on:

jobs:
test:
continue-on-error: true
runs-on: ubuntu-latest
services:
redis:
@@ -24,22 +25,84 @@ jobs:
- 2.6
- 2.7
- "3.0"
- 3.1
- head
- jruby-9.1.17.0
- jruby-9.2.9.0
- jruby-9.2.19.0
- "jruby-9.2.20.0"
- jruby-9.3.3.0
resque-version:
- "master"
- "~> 2.0.0"
- "~> 2.2.0"
- "~> 1.27"
rufus-scheduler:
- "3.2"
- "3.4"
- "3.5"
- "3.6"
exclude:
- ruby-version: head
rufus-scheduler: 3.2

- ruby-version: 2.3
resque-version: 1.27
rufus-scheduler: 3.4
- ruby-version: 2.3
resque-version: 1.27
rufus-scheduler: 3.5
- ruby-version: 2.5
resque-version: 2.2.0
rufus-scheduler: 3.5
- ruby-version: 2.5
resque-version: master
rufus-scheduler: 3.2

- ruby-version: jruby-9.1.17.0
resque-version: master
rufus-scheduler: 3.4
- ruby-version: jruby-9.1.17.0
resque-version: master
rufus-scheduler: 3.5
- ruby-version: jruby-9.1.17.0
resque-version: 2.2.0
rufus-scheduler: 3.2

- ruby-version: jruby-9.2.20.0
resque-version: 2.0.0
rufus-scheduler: 3.4
- ruby-version: jruby-9.2.20.0
resque-version: 2.0.0
rufus-scheduler: 3.5

- ruby-version: jruby-9.3.3.0
resque-version: 2.2.0
rufus-scheduler: 3.5

- ruby-version: jruby-9.3.3.0
resque-version: master
rufus-scheduler: 3.2
- ruby-version: jruby-9.3.3.0
resque-version: master
rufus-scheduler: 3.4
- ruby-version: jruby-9.3.3.0
resque-version: master
rufus-scheduler: 3.5
- ruby-version: jruby-9.3.3.0
resque-version: master
rufus-scheduler: 3.6

- ruby-version: jruby-9.3.3.0
resque-version: 1.27
rufus-scheduler: 3.2
- ruby-version: jruby-9.3.3.0
resque-version: 1.27
rufus-scheduler: 3.5
env:
RESQUE: "${{ matrix.resque-version }}"
RUFUS_SCHEDULER: "${{ matrix.rufus-scheduler }}"
COVERAGE: 1
JRUBY_OPTS: ""
RUBYOPT: "-W0"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: "${{ matrix.ruby-version }}"
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ Resque Scheduler authors
- Brian Landau
- Brian P O'Rourke
- Carlos Antonio da Silva
- Chris Bisnett
- Chris Kampmeier
- DJ Hartman
- Damon P. Cortesi
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,9 +2,14 @@

**ATTN**: This project uses [semantic versioning](http://semver.org/).

## Unreleased
## [Unreleased]
### Changed
- Remove support for Ruby < 2.3
- Configuration to use a set of truthy values to enable boolean settings instead of simply existence
- Add `delay_or_enqueue_at` for delaying existing jobs or creating a new job
- Unblock rufus-scheduler lock on lower than 3.7 by fixing scheduler shutdown

## [4.5.0]
## [4.5.0] - 2021-09-25
### Added
- Support Ruby 3
- Add optional argument to `remove_schedule` to control reloading of the schedule
@@ -443,7 +448,8 @@
### Added
- Initial release

[Unreleased]: https://github.com/resque/resque-scheduler/compare/v4.4.0...HEAD
[Unreleased]: https://github.com/resque/resque-scheduler/compare/v4.5.0...HEAD
[4.5.0]: https://github.com/resque/resque-scheduler/compare/v4.4.0...v4.5.0
[4.4.0]: https://github.com/resque/resque-scheduler/compare/v4.3.1...v4.4.0
[4.3.1]: https://github.com/resque/resque-scheduler/compare/v4.3.0...v4.3.1
[4.3.0]: https://github.com/resque/resque-scheduler/compare/v4.2.1...v4.3.0
12 changes: 9 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# vim:fileencoding=utf-8
source 'https://rubygems.org'

case req = ENV['RESQUE']
when nil
case resque_version = ENV.fetch('RESQUE', 'master')
when 'master'
gem 'resque', git: 'https://github.com/resque/resque'
else
gem 'resque', req
gem 'resque', resque_version
end

case rufus_scheduler_version = ENV.fetch('RUFUS_SCHEDULER', '3.6')
when 'master'
gem 'rufus-scheduler', git: 'https://github.com/jmettraux/rufus-scheduler'
else
gem 'rufus-scheduler', rufus_scheduler_version
end

gemspec
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@ since the jobs are stored in a redis sorted set (zset). I can't imagine this
being an issue for someone since redis is stupidly fast even at log(n), but full
disclosure is always best.

#### Removing Delayed jobs
#### Removing Delayed Jobs

If you have the need to cancel a delayed job, you can do like so:

@@ -255,6 +255,49 @@ Resque.enqueue_delayed_selection { |args| args[0]['account_id'] == current_accou
Resque.enqueue_delayed_selection { |args| args[0]['user_id'] == current_user.id }
```

#### Updating Delayed Jobs

Previously delayed jobs may be delayed even further into the future like so:

```ruby
# after you've enqueued a job like:
Resque.enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
# delay running the job until two minutes from now
Resque.delay_or_enqueue_at(2.minutes.from_now, SendNotifications, :user_id => current_user.id)
```

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:

```ruby
Resque.delay_or_enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
```

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.

```ruby
# enqueue multiple jobs with different delay timestamps
Resque.enqueue_at(1.minute.from_now, SendNotifications, :user_id => current_user.id)
Resque.enqueue_at(2.minutes.from_now, SendNotifications, :user_id => current_user.id)

# delay running the two jobs until 5 minutes from now
Resque.delay_or_enqueue_at(5.minutes.from_now, SendNotifications, :user_id => current_user.id)
```

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:

```ruby
# Send a notification when an event is created.
# app/models/event.rb
after_commit on: :create do
Resque.delay_or_enqueue_in(2.minutes, SendNotifications, :user_id => user.id)
end
```

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.

Read more in the [original PR](https://github.com/resque/resque-scheduler/pull/645)


### Scheduled Jobs (Recurring Jobs)

Scheduled (or recurring) jobs are logically no different than a standard cron
@@ -304,7 +347,6 @@ If you would like to setup a job that is executed manually you can configure lik
```yaml
ImportOrdersManual:
description: 'Import Amazon Orders Manual'
custom_job_class: 'AmazonMws::ImportOrdersJob'
never: "* * * * *"
queue: high
@@ -615,7 +657,7 @@ Now make sure you're passing that file to resque-web like so:

### Running in the background

(Only supported with ruby >= 1.9). There are scenarios where it's helpful for
There are scenarios where it's helpful for
the resque worker to run itself in the background (usually in combination with
PIDFILE). Use the BACKGROUND option so that rake will return as soon as the
worker is started.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ Rake::TestTask.new do |t|
o << "--seed #{ENV['SEED']} " if ENV['SEED']
o << '--verbose ' if ENV['VERBOSE']
end
t.warning = false
end

YARD::Rake::YardocTask.new
3 changes: 1 addition & 2 deletions lib/resque/scheduler.rb
Original file line number Diff line number Diff line change
@@ -256,7 +256,7 @@ def enqueue_from_config(job_config)
if job_klass && job_klass != 'Resque::Job'
# The custom job class API must offer a static "scheduled" method. If
# the custom job class can not be constantized (via a requeue call
# from the web perhaps), fall back to enqueing normally via
# from the web perhaps), fall back to enqueuing normally via
# Resque::Job.create.
begin
Resque::Scheduler::Util.constantize(job_klass).scheduled(
@@ -382,7 +382,6 @@ def handle_signals_with_operation

def stop_rufus_scheduler
rufus_scheduler.shutdown(:wait)
rufus_scheduler.join
end

def before_shutdown
Loading