que 1.4.1 → 2.0.0.beta1

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: 6f274711739c76ae8ec986e367c39eb3e39cadeefa5be57bb685b3b34f86e3f8
4
- data.tar.gz: be68db2fe99b2156c68cdc7470ec536c3d5f0104eb908298dad77f9cb41acaf2
3
+ metadata.gz: 382ef488f1aa4e91e0ef2b617ad03bdfee4001020a71ef31662cd99e52e34915
4
+ data.tar.gz: 1d59264e766fd94aeeec463d7ea7f4cf76c867bc356df553f7d9e7a705095da6
5
5
  SHA512:
6
- metadata.gz: abda6691442a612777c9dbe8ddd60678a106526a40f9b9293c3f66adc70eb66448b2dc42359a6adc1d7cf7b142c8950fcb65a8b14b1eabee33fa209607bc1520
7
- data.tar.gz: 69884364862c515b7f317cb05ea3b7f8ce3f367e0266405fc5d1cbc61471a7f6e378f55eb0a271c62b82833a9f7d2feb27ec0fe433e28d9ee855bb7239ab4745
6
+ metadata.gz: 03b72732163fc9d24fe91a5dcbc18986c7dead94fe0a8d28e66727cf93739e9a47c4ab9f39239ff3776b63f24339c2266becc2b00bd1d45efc15f3a064580466
7
+ data.tar.gz: 87d9701463b8e3ac5a7ba62cd376e4508a856de0c69b04e7dcdaf7d481746552d4d4762026b70efe4a910b6a7de9243dc98eeb6e43d4e7fbc3d1065b0b6a941e
@@ -7,11 +7,19 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby_version: [2.5.x, 2.6.x, 2.7.x]
11
- gemfile: ["4.2", "5.2", "6.0"]
12
- postgres_version: [9, 10, 11, 12]
13
- exclude:
14
- - { gemfile: "4.2", ruby_version: "2.7.x" }
10
+ ruby_version: ['2.7', '3.0', '3.1']
11
+ rails_gemfile: ['6.0', '6.1']
12
+ postgres_version: ['14']
13
+ include:
14
+ # Postgres versions
15
+ - { ruby_version: '3.1', rails_gemfile: '6.1', postgres_version: '9' }
16
+ - { ruby_version: '3.1', rails_gemfile: '6.1', postgres_version: '10' }
17
+ - { ruby_version: '3.1', rails_gemfile: '6.1', postgres_version: '11' }
18
+ - { ruby_version: '3.1', rails_gemfile: '6.1', postgres_version: '12' }
19
+ - { ruby_version: '3.1', rails_gemfile: '6.1', postgres_version: '13' }
20
+ - { ruby_version: '3.1', rails_gemfile: '6.1', postgres_version: '14' }
21
+ exclude: []
22
+ name: "Test: Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_gemfile }}, PostgreSQL ${{ matrix.postgres_version }}"
15
23
  services:
16
24
  db:
17
25
  image: postgres:${{ matrix.postgres_version }}
@@ -24,16 +32,16 @@ jobs:
24
32
  --health-timeout 5s
25
33
  --health-retries 5
26
34
  steps:
27
- - uses: actions/checkout@v1
35
+ - uses: actions/checkout@v2
28
36
  - name: Set up Ruby
29
- uses: actions/setup-ruby@v1
37
+ uses: ruby/setup-ruby@v1
30
38
  with:
31
39
  ruby-version: ${{ matrix.ruby_version }}
32
40
  - name: Test with Rake
33
41
  env:
34
42
  PGHOST: 127.0.0.1
35
43
  PGUSER: postgres
36
- BUNDLE_GEMFILE: spec/gemfiles/Gemfile.${{ matrix.gemfile }}
44
+ BUNDLE_GEMFILE: spec/gemfiles/Gemfile-rails-${{ matrix.rails_gemfile }}
37
45
  run: |
38
46
  sudo apt-get -yqq install libpq-dev postgresql-client
39
47
  createdb que-test
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.1
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <!-- MarkdownTOC autolink=true -->
4
4
 
5
- - [1.4.1 \(2022-07-24\)](#141-2022-07-24)
5
+ - [2.0.0.beta1 \(2022-03-24\)](#200beta1-2022-03-24)
6
6
  - [1.4.0 \(2022-03-23\)](#140-2022-03-23)
7
7
  - [1.3.1 \(2022-02-25\)](#131-2022-02-25)
8
8
  - [1.3.0 \(2022-02-25\)](#130-2022-02-25)
@@ -52,10 +52,58 @@
52
52
 
53
53
  <!-- /MarkdownTOC -->
54
54
 
55
- ## 1.4.1 (2022-07-24)
55
+ ## 2.0.0.beta1 (2022-03-24)
56
56
 
57
- - **Added**
58
- + Added Ruby version requirement of < 3. For Ruby 3 compatibility, upgrade to Que 2 - [upgrade process](https://github.com/que-rb/que/blob/master/CHANGELOG.md#200beta1-2022-03-24)
57
+ **Preliminary release of Ruby 3 support**
58
+
59
+ **Notable changes**:
60
+
61
+ * Support for Ruby 3 introduced
62
+ * Database schema has changed to split the job arguments `args` column into `args` and `kwargs` columns, for reliable args and kwargs splitting for Ruby 3.
63
+ - The job schema version is now 2. Note that job schema version is distinct from database schema version and Que version. The `job_schema_version` column of the `que_jobs` table no longer defaults and has a not null constraint, so when manually inserting jobs into the table, this must be specified as `2`. If you have a gem that needs to support multiple Que versions, best not to blindly use the value of `Que.job_schema_version`; instead have different code paths depending on the value of `Que.job_schema_version`. You could also use this to know whether keyword arguments are in `args` or `kwargs`.
64
+ * Passing a hash literal as the last job argument to be splatted into job keyword arguments is no longer supported.
65
+ * Dropped support for providing job options as top-level keyword arguments to `Job.enqueue`, i.e. `queue`, `priority`, `run_at`, `job_class`, and `tags`. Job options now need to be nested under the `job_options` keyword argument instead. See [#336](https://github.com/que-rb/que/pull/336)
66
+ * Dropped support for Ruby < 2.7
67
+ * Dropped support for Rails < 6.0
68
+ * The `#by_args` method on the Job model (for both Sequel and ActiveRecord) now searches based on both args and kwargs, but it performs a subset match instead of an exact match. For instance, if your job was scheduled with `'a', 'b', 'c', foo: 'bar', baz: 1`, `by_args('a', 'b', baz: 1)` would find and return the job.
69
+ * This release contains a database migration. You will need to migrate Que to the latest database schema version (6). For example, on ActiveRecord and Rails 6:
70
+
71
+ ```ruby
72
+ class UpdateQueTablesToVersion6 < ActiveRecord::Migration[6.0]
73
+ def up
74
+ Que.migrate!(version: 6)
75
+ end
76
+
77
+ def down
78
+ Que.migrate!(version: 5)
79
+ end
80
+ end
81
+ ```
82
+
83
+ **Recommended upgrade process**:
84
+
85
+ When using Que 2.x, a job enqueued with Ruby 2.7 will run as expected on Ruby 3. We recommend:
86
+
87
+ 1. Upgrade your project to the latest 1.x version of Que (1.3.1+)
88
+ - IMPORTANT: adds support for zero downtime upgrade to Que 2.x, see changelog below
89
+ 2. Upgrade your project to Ruby 2.7 and Rails 6.x if it is not already
90
+ 3. Upgrade your project to Que 2.x but stay on Ruby 2.7
91
+ - IMPORTANT: You will need to continue to run Que 1.x workers until all jobs enqueued using Que 1.x (i.e. with a `job_schema_version` of `1`) have been finished. See below
92
+ 4. Upgrade your project to Ruby 3
93
+
94
+ *NOTES:*
95
+
96
+ * If you were already running Ruby 2.7 and were not passing a hash literal as the last job argument, you *may* be able to upgrade a running system without draining the queue, though this is not recommended.
97
+ * For all other cases, you will need to follow the recommended process above or first completely drain the queue (stop enqueuing new jobs and finish processing any jobs in the database, including cleaning out any expired jobs) before upgrading.
98
+
99
+ **Deploying Que 1.x and 2.x workers simultaneously**:
100
+
101
+ To run workers with two different versions of Que, you'll probably need to temporarily duplicate your gem bundle, with the Que version being the only difference. e.g.:
102
+
103
+ - Copy your `Gemfile` and `Gemfile.lock` into a directory called `que-1-gemfile`
104
+ - Set a suitable Que version in each `Gemfile`
105
+ - Update the bundle at `que-1-gemfile/Gemfile.lock` using `BUNDLE_GEMFILE=que-1-gemfile/Gemfile bundle`
106
+ - Create a second deployment of Que, but with your `que` command prefixed with `BUNDLE_GEMFILE=que-1-gemfile/Gemfile`
59
107
 
60
108
  ## 1.4.0 (2022-03-23)
61
109
 
@@ -67,7 +115,7 @@
67
115
  * It became used in 1.0.0.beta4, and that changelog entry has been updated to reflect this.
68
116
  - **Documentation**:
69
117
  + Reformatted the changelog to be more consistent, including adding links to all issue/PR numbers. [#347](https://github.com/que-rb/que/pull/347)
70
-
118
+ +
71
119
  ## 1.3.1 (2022-02-25)
72
120
 
73
121
  Unfortunately, v1.3.0 was broken. Follow its upgrade instructions, but use this version instead.
data/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM ruby:2.7.5-slim-buster@sha256:4cbbe2fba099026b243200aa8663f56476950cc64ccd91d7aaccddca31e445b5 AS base
1
+ FROM ruby:3.1.1-slim-buster@sha256:2ada3e4fe7b1703c9333ad4eb9fc12c1d4d60bce0f981281b2151057e928d9ad AS base
2
2
 
3
3
  # Install libpq-dev in our base layer, as it's needed in all environments
4
4
  RUN apt-get update \
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Que ![tests](https://github.com/que-rb/que/workflows/tests/badge.svg)
2
2
 
3
- **This README and the rest of the docs on the master branch all refer to Que 1.0. If you're using version 0.x, please refer to the docs on [the 0.x branch](https://github.com/que-rb/que/tree/0.x).**
3
+ **This README and the rest of the docs on the master branch all refer to Que 2.x. For older versions, please refer to the docs on the respective branches: [1.x](https://github.com/que-rb/que/tree/1.x), or [0.x](https://github.com/que-rb/que/tree/0.x).**
4
4
 
5
5
  *TL;DR: Que is a high-performance job queue that improves the reliability of your application by protecting your jobs with the same [ACID guarantees](https://en.wikipedia.org/wiki/ACID) as the rest of your data.*
6
6
 
@@ -23,9 +23,9 @@ Que's secondary goal is performance. The worker process is multithreaded, so tha
23
23
 
24
24
  Compatibility:
25
25
 
26
- - MRI Ruby 2.2+, < 3 (for Ruby 3, Que 2+ is required)
26
+ - MRI Ruby 2.7+
27
27
  - PostgreSQL 9.5+
28
- - Rails 4.1+ (optional)
28
+ - Rails 6.0+ (optional)
29
29
 
30
30
  **Please note** - Que's job table undergoes a lot of churn when it is under high load, and like any heavily-written table, is susceptible to bloat and slowness if Postgres isn't able to clean it up. The most common cause of this is long-running transactions, so it's recommended to try to keep all transactions against the database housing Que's job table as short as possible. This is good advice to remember for any high-activity database, but bears emphasizing when using tables that undergo a lot of writes.
31
31
 
@@ -54,12 +54,12 @@ gem install que
54
54
  First, create the queue schema in a migration. For example:
55
55
 
56
56
  ```ruby
57
- class CreateQueSchema < ActiveRecord::Migration[5.0]
57
+ class CreateQueSchema < ActiveRecord::Migration[6.0]
58
58
  def up
59
59
  # Whenever you use Que in a migration, always specify the version you're
60
60
  # migrating to. If you're unsure what the current version is, check the
61
61
  # changelog.
62
- Que.migrate!(version: 5)
62
+ Que.migrate!(version: 6)
63
63
  end
64
64
 
65
65
  def down
@@ -117,10 +117,10 @@ end
117
117
  You can also add options to run the job after a specific time, or with a specific priority:
118
118
 
119
119
  ```ruby
120
- ChargeCreditCard.enqueue card.id, user_id: current_user.id, run_at: 1.day.from_now, priority: 5
120
+ ChargeCreditCard.enqueue(card.id, user_id: current_user.id, job_options: { run_at: 1.day.from_now, priority: 5 })
121
121
  ```
122
122
  ## Running the Que Worker
123
- In order to process jobs, you must start a separate worker process outside of your main server.
123
+ In order to process jobs, you must start a separate worker process outside of your main server.
124
124
 
125
125
  ```bash
126
126
  bundle exec que
@@ -142,7 +142,7 @@ You may need to pass que a file path to require so that it can load your app. Qu
142
142
 
143
143
  If you're using ActiveRecord to dump your database's schema, please [set your schema_format to :sql](http://guides.rubyonrails.org/migrations.html#types-of-schema-dumps) so that Que's table structure is managed correctly. This is a good idea regardless, as the `:ruby` schema format doesn't support many of PostgreSQL's advanced features.
144
144
 
145
- Pre-1.0, the default queue name needed to be configured in order for Que to work out of the box with Rails. In 1.0 the default queue name is now 'default', as Rails expects, but when Rails enqueues some types of jobs it may try to use another queue name that isn't worked by default. You can either:
145
+ Pre-1.0, the default queue name needed to be configured in order for Que to work out of the box with Rails. As of 1.0 the default queue name is now 'default', as Rails expects, but when Rails enqueues some types of jobs it may try to use another queue name that isn't worked by default. You can either:
146
146
 
147
147
  - [Configure Rails](https://guides.rubyonrails.org/configuring.html) to send all internal job types to the 'default' queue by adding the following to `config/application.rb`:
148
148
 
@@ -220,7 +220,7 @@ OUTPUT
220
220
 
221
221
  locker =
222
222
  begin
223
- Que::Locker.new(options)
223
+ Que::Locker.new(**options)
224
224
  rescue => e
225
225
  output.puts(e.message)
226
226
  return 1
data/docker-compose.yml CHANGED
@@ -10,13 +10,14 @@ services:
10
10
  - db
11
11
  volumes:
12
12
  - .:/work
13
- - ruby-2.7.5-gem-cache:/usr/local/bundle
13
+ - ruby-3.1.1-gem-cache:/usr/local/bundle
14
14
  - ~/.docker-rc.d/:/.docker-rc.d/:ro
15
15
  working_dir: /work
16
16
  entrypoint: /work/scripts/docker-entrypoint
17
17
  command: bash
18
18
  environment:
19
19
  DATABASE_URL: postgres://que:que@db/que-test
20
+ USE_RAILS: ~
20
21
 
21
22
  db:
22
23
  image: "postgres:${POSTGRES_VERSION-13}"
@@ -43,4 +44,4 @@ services:
43
44
 
44
45
  volumes:
45
46
  db-data: ~
46
- ruby-2.7.5-gem-cache: ~
47
+ ruby-3.1.1-gem-cache: ~
data/docs/README.md CHANGED
@@ -128,8 +128,8 @@ There are other docs to read if you're using [Sequel](#using-sequel) or [plain P
128
128
  After you've connected Que to the database, you can manage the jobs table. You'll want to migrate to a specific version in a migration file, to ensure that they work the same way even when you upgrade Que in the future:
129
129
 
130
130
  ```ruby
131
- # Update the schema to version #5.
132
- Que.migrate!(version: 5)
131
+ # Update the schema to version #6.
132
+ Que.migrate!(version: 6)
133
133
 
134
134
  # Remove Que's jobs table entirely.
135
135
  Que.migrate!(version: 0)
@@ -441,7 +441,7 @@ que -q default -q credit_cards
441
441
  Then you can set jobs to be enqueued in that queue specifically:
442
442
 
443
443
  ```ruby
444
- ProcessCreditCard.enqueue current_user.id, queue: 'credit_cards'
444
+ ProcessCreditCard.enqueue(current_user.id, job_options: { queue: 'credit_cards' })
445
445
 
446
446
  # Or:
447
447
 
@@ -455,7 +455,7 @@ end
455
455
  In some cases, the ProcessCreditCard class may not be defined in the application that is enqueueing the job. In that case, you can specify the job class as a string:
456
456
 
457
457
  ```ruby
458
- Que.enqueue current_user.id, job_class: 'ProcessCreditCard', queue: 'credit_cards'
458
+ Que.enqueue(current_user.id, job_options: { job_class: 'ProcessCreditCard', queue: 'credit_cards' })
459
459
  ```
460
460
 
461
461
  ## Shutting Down Safely
@@ -549,7 +549,7 @@ require 'que'
549
549
  Sequel.migration do
550
550
  up do
551
551
  Que.connection = self
552
- Que.migrate!(version: 5)
552
+ Que.migrate!(version: 6)
553
553
  end
554
554
  down do
555
555
  Que.connection = self
@@ -585,7 +585,7 @@ Sequel automatically wraps model persistance actions (create, update, destroy) i
585
585
 
586
586
  ## Using Que With ActiveJob
587
587
 
588
- You can include `Que::ActiveJob::JobExtensions` into your `ApplicationJob` subclass to get support for all of Que's
588
+ You can include `Que::ActiveJob::JobExtensions` into your `ApplicationJob` subclass to get support for all of Que's
589
589
  [helper methods](#job-helper-methods). These methods will become no-ops if you use a queue adapter that isn't Que, so if you like to use a different adapter in development they shouldn't interfere.
590
590
 
591
591
  Additionally, including `Que::ActiveJob::JobExtensions` lets you define a run() method that supports keyword arguments.
@@ -12,8 +12,10 @@ module Que
12
12
  end
13
13
 
14
14
  def perform(*args)
15
+ args, kwargs = Que.split_out_ruby2_keywords(args)
16
+
15
17
  Que.internal_log(:active_job_perform, self) do
16
- {args: args}
18
+ {args: args, kwargs: kwargs}
17
19
  end
18
20
 
19
21
  _run(
@@ -21,7 +23,12 @@ module Que
21
23
  que_filter_args(
22
24
  args.map { |a| a.is_a?(Hash) ? a.deep_symbolize_keys : a }
23
25
  )
24
- )
26
+ ),
27
+ kwargs: Que.recursively_freeze(
28
+ que_filter_args(
29
+ kwargs.deep_symbolize_keys,
30
+ )
31
+ ),
25
32
  )
26
33
  end
27
34
 
@@ -53,37 +60,46 @@ module Que
53
60
  # A module that we mix into ActiveJob's wrapper for Que::Job, to maintain
54
61
  # backwards-compatibility with internal changes we make.
55
62
  module WrapperExtensions
56
- # The Rails adapter (built against a pre-1.0 version of this gem)
57
- # assumes that it can access a job's id via job.attrs["job_id"]. So,
58
- # oblige it.
59
- def attrs
60
- {"job_id" => que_attrs[:id]}
63
+ module ClassMethods
64
+ # We've dropped support for job options supplied as top-level keywords, but ActiveJob's QueAdapter still uses them. So we have to move them into the job_options hash ourselves.
65
+ def enqueue(args, priority:, queue:, run_at: nil)
66
+ super(args, job_options: { priority: priority, queue: queue, run_at: run_at })
67
+ end
61
68
  end
62
69
 
63
- def run(args)
64
- # Our ActiveJob extensions expect to be able to operate on the actual
65
- # job object, but there's no way to access it through ActiveJob. So,
66
- # scope it to the current thread. It's a bit messy, but it's the best
67
- # option under the circumstances (doesn't require hacking ActiveJob in
68
- # any more extensive way).
70
+ module InstanceMethods
71
+ # The Rails adapter (built against a pre-1.0 version of this gem)
72
+ # assumes that it can access a job's id via job.attrs["job_id"]. So,
73
+ # oblige it.
74
+ def attrs
75
+ {"job_id" => que_attrs[:id]}
76
+ end
77
+
78
+ def run(args)
79
+ # Our ActiveJob extensions expect to be able to operate on the actual
80
+ # job object, but there's no way to access it through ActiveJob. So,
81
+ # scope it to the current thread. It's a bit messy, but it's the best
82
+ # option under the circumstances (doesn't require hacking ActiveJob in
83
+ # any more extensive way).
69
84
 
70
- # There's no reason this logic should ever nest, because it wouldn't
71
- # make sense to run a worker inside of a job, but even so, assert that
72
- # nothing absurd is going on.
73
- Que.assert NilClass, Thread.current[:que_current_job]
85
+ # There's no reason this logic should ever nest, because it wouldn't
86
+ # make sense to run a worker inside of a job, but even so, assert that
87
+ # nothing absurd is going on.
88
+ Que.assert NilClass, Thread.current[:que_current_job]
74
89
 
75
- begin
76
- Thread.current[:que_current_job] = self
90
+ begin
91
+ Thread.current[:que_current_job] = self
77
92
 
78
- # We symbolize the args hash but ActiveJob doesn't like that :/
79
- super(args.deep_stringify_keys)
80
- ensure
81
- # Also assert that the current job state was only removed now, but
82
- # unset the job first so that an assertion failure doesn't mess up
83
- # the state any more than it already has.
84
- current = Thread.current[:que_current_job]
85
- Thread.current[:que_current_job] = nil
86
- Que.assert(self, current)
93
+ # We symbolize the args hash but ActiveJob doesn't like that :/
94
+ super(args.deep_stringify_keys)
95
+ ensure
96
+ # Also assert that the current job state was only removed now, but
97
+ # unset the job first so that an assertion failure doesn't mess up
98
+ # the state any more than it already has.
99
+ current = Thread.current[:que_current_job]
100
+ Thread.current[:que_current_job] = nil
101
+ Que.assert(self, current)
102
+ end
87
103
  end
88
104
  end
89
105
  end
@@ -92,6 +108,7 @@ end
92
108
 
93
109
  class ActiveJob::QueueAdapters::QueAdapter
94
110
  class JobWrapper < Que::Job
95
- prepend Que::ActiveJob::WrapperExtensions
111
+ extend Que::ActiveJob::WrapperExtensions::ClassMethods
112
+ prepend Que::ActiveJob::WrapperExtensions::InstanceMethods
96
113
  end
97
114
  end
@@ -39,8 +39,8 @@ module Que
39
39
  where("que_jobs.data @> ?", JSON.dump(tags: [tag]))
40
40
  end
41
41
 
42
- def by_args(*args)
43
- where("que_jobs.args @> ?", JSON.dump(args))
42
+ def by_args(*args, **kwargs)
43
+ where("que_jobs.args @> ? AND que_jobs.kwargs @> ?", JSON.dump(args), JSON.dump(kwargs))
44
44
  end
45
45
  end
46
46
  end
data/lib/que/job.rb CHANGED
@@ -12,7 +12,7 @@ module Que
12
12
  SQL[:insert_job] =
13
13
  %{
14
14
  INSERT INTO public.que_jobs
15
- (queue, priority, run_at, job_class, args, data, job_schema_version)
15
+ (queue, priority, run_at, job_class, args, kwargs, data, job_schema_version)
16
16
  VALUES
17
17
  (
18
18
  coalesce($1, 'default')::text,
@@ -21,6 +21,7 @@ module Que
21
21
  $4::text,
22
22
  coalesce($5, '[]')::jsonb,
23
23
  coalesce($6, '{}')::jsonb,
24
+ coalesce($7, '{}')::jsonb,
24
25
  #{Que.job_schema_version}
25
26
  )
26
27
  RETURNING *
@@ -56,13 +57,10 @@ module Que
56
57
  :priority,
57
58
  :run_at
58
59
 
59
- def enqueue(
60
- *args,
61
- job_options: {},
62
- **arg_opts
63
- )
64
- arg_opts, job_options = _extract_job_options(arg_opts, job_options.dup)
65
- args << arg_opts if arg_opts.any?
60
+ def enqueue(*args)
61
+ args, kwargs = Que.split_out_ruby2_keywords(args)
62
+
63
+ job_options = kwargs.delete(:job_options) || {}
66
64
 
67
65
  if job_options[:tags]
68
66
  if job_options[:tags].length > MAXIMUM_TAGS_COUNT
@@ -81,6 +79,7 @@ module Que
81
79
  priority: job_options[:priority] || resolve_que_setting(:priority),
82
80
  run_at: job_options[:run_at] || resolve_que_setting(:run_at),
83
81
  args: Que.serialize_json(args),
82
+ kwargs: Que.serialize_json(kwargs),
84
83
  data: job_options[:tags] ? Que.serialize_json(tags: job_options[:tags]) : "{}",
85
84
  job_class: \
86
85
  job_options[:job_class] || name ||
@@ -89,27 +88,31 @@ module Que
89
88
 
90
89
  if attrs[:run_at].nil? && resolve_que_setting(:run_synchronously)
91
90
  attrs[:args] = Que.deserialize_json(attrs[:args])
91
+ attrs[:kwargs] = Que.deserialize_json(attrs[:kwargs])
92
92
  attrs[:data] = Que.deserialize_json(attrs[:data])
93
93
  _run_attrs(attrs)
94
94
  else
95
95
  values =
96
96
  Que.execute(
97
97
  :insert_job,
98
- attrs.values_at(:queue, :priority, :run_at, :job_class, :args, :data),
98
+ attrs.values_at(:queue, :priority, :run_at, :job_class, :args, :kwargs, :data),
99
99
  ).first
100
-
101
100
  new(values)
102
101
  end
103
102
  end
103
+ ruby2_keywords(:enqueue) if respond_to?(:ruby2_keywords, true)
104
104
 
105
105
  def run(*args)
106
106
  # Make sure things behave the same as they would have with a round-trip
107
107
  # to the DB.
108
+ args, kwargs = Que.split_out_ruby2_keywords(args)
108
109
  args = Que.deserialize_json(Que.serialize_json(args))
110
+ kwargs = Que.deserialize_json(Que.serialize_json(kwargs))
109
111
 
110
112
  # Should not fail if there's no DB connection.
111
- _run_attrs(args: args)
113
+ _run_attrs(args: args, kwargs: kwargs)
112
114
  end
115
+ ruby2_keywords(:run) if respond_to?(:ruby2_keywords, true)
113
116
 
114
117
  def resolve_que_setting(setting, *args)
115
118
  value = send(setting) if respond_to?(setting)
@@ -136,27 +139,6 @@ module Que
136
139
  end
137
140
  end
138
141
  end
139
-
140
- def _extract_job_options(arg_opts, job_options)
141
- deprecated_job_option_names = []
142
-
143
- %i[queue priority run_at job_class tags].each do |option_name|
144
- next unless arg_opts.key?(option_name) && job_options[option_name].nil?
145
-
146
- job_options[option_name] = arg_opts.delete(option_name)
147
- deprecated_job_option_names << option_name
148
- end
149
-
150
- _log_job_options_deprecation(deprecated_job_option_names)
151
-
152
- [arg_opts, job_options]
153
- end
154
-
155
- def _log_job_options_deprecation(deprecated_job_option_names)
156
- return unless deprecated_job_option_names.any?
157
-
158
- warn "Passing job options like (#{deprecated_job_option_names.join(', ')}) to `JobClass.enqueue` as top level keyword args has been deprecated and will be removed in version 2.0. Please wrap job options in an explicit `job_options` keyword arg instead."
159
- end
160
142
  end
161
143
 
162
144
  # Set up some defaults.
@@ -39,12 +39,16 @@ module Que
39
39
  # Run the job with error handling and cleanup logic. Optionally support
40
40
  # overriding the args, because it's necessary when jobs are invoked from
41
41
  # ActiveJob.
42
- def _run(args: nil, reraise_errors: false)
42
+ def _run(args: nil, kwargs: nil, reraise_errors: false)
43
43
  if args.nil? && que_target
44
44
  args = que_target.que_attrs.fetch(:args)
45
45
  end
46
46
 
47
- run(*args)
47
+ if kwargs.nil? && que_target
48
+ kwargs = que_target.que_attrs.fetch(:kwargs)
49
+ end
50
+
51
+ run(*args, **kwargs)
48
52
  default_resolve_action if que_target && !que_target.que_resolved
49
53
  rescue => error
50
54
  raise error unless que_target
@@ -0,0 +1,8 @@
1
+ DROP INDEX que_jobs_kwargs_gin_idx;
2
+ ALTER TABLE que_jobs DROP COLUMN kwargs;
3
+
4
+ ALTER INDEX que_poll_idx RENAME TO que_poll_idx_with_job_schema_version;
5
+ CREATE INDEX que_poll_idx ON que_jobs (queue, priority, run_at, id) WHERE (finished_at IS NULL AND expired_at IS NULL);
6
+
7
+ ALTER TABLE que_jobs ALTER COLUMN job_schema_version SET DEFAULT 1;
8
+ ALTER TABLE que_jobs ALTER COLUMN job_schema_version DROP NOT NULL;
@@ -0,0 +1,8 @@
1
+ ALTER TABLE que_jobs ADD COLUMN kwargs JSONB NOT NULL DEFAULT '{}';
2
+ CREATE INDEX que_jobs_kwargs_gin_idx ON que_jobs USING gin (kwargs jsonb_path_ops);
3
+
4
+ DROP INDEX que_poll_idx;
5
+ ALTER INDEX que_poll_idx_with_job_schema_version RENAME TO que_poll_idx;
6
+
7
+ ALTER TABLE que_jobs ALTER COLUMN job_schema_version DROP DEFAULT;
8
+ ALTER TABLE que_jobs ALTER COLUMN job_schema_version SET NOT NULL;
@@ -4,7 +4,7 @@ module Que
4
4
  module Migrations
5
5
  # In order to ship a schema change, add the relevant up and down sql files
6
6
  # to the migrations directory, and bump the version here.
7
- CURRENT_VERSION = 5
7
+ CURRENT_VERSION = 6
8
8
 
9
9
  class << self
10
10
  def migrate!(version:)
@@ -40,8 +40,11 @@ module Que
40
40
  where(QUALIFIED_TABLE[:data].pg_jsonb.contains(JSON.dump(tags: [tag])))
41
41
  end
42
42
 
43
- def by_args(*args)
44
- where(QUALIFIED_TABLE[:args].pg_jsonb.contains(JSON.dump(args)))
43
+ def by_args(*args, **kwargs)
44
+ where(
45
+ QUALIFIED_TABLE[:args].pg_jsonb.contains(JSON.dump(args)) &
46
+ QUALIFIED_TABLE[:kwargs].pg_jsonb.contains(JSON.dump(kwargs))
47
+ )
45
48
  end
46
49
  end
47
50
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Temporary module allowing ruby2 keyword args to be extracted from an *args splat
4
+ # Allows us to ensure consistent behaviour when running on ruby 2 vs ruby 3
5
+ # We can remove this if/when we drop support for ruby 2
6
+
7
+ require 'json'
8
+
9
+ module Que
10
+ module Utils
11
+ module Ruby2Keywords
12
+ def split_out_ruby2_keywords(args)
13
+ return [args, {}] unless args.last&.is_a?(Hash) && Hash.ruby2_keywords_hash?(args.last)
14
+
15
+ [args[0..-2], args.last]
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/que/version.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Que
4
- VERSION = '1.4.1'
4
+ VERSION = '2.0.0.beta1'
5
5
 
6
6
  def self.job_schema_version
7
- 1
7
+ 2
8
8
  end
9
9
  end
data/lib/que/worker.rb CHANGED
@@ -125,7 +125,7 @@ module Que
125
125
  log_message[:event] = :job_worked
126
126
  end
127
127
 
128
- Que.log(log_message)
128
+ Que.log(**log_message)
129
129
  end
130
130
 
131
131
  instance
data/lib/que.rb CHANGED
@@ -29,6 +29,7 @@ module Que
29
29
  require_relative 'que/utils/logging'
30
30
  require_relative 'que/utils/middleware'
31
31
  require_relative 'que/utils/queue_management'
32
+ require_relative 'que/utils/ruby2_keywords'
32
33
  require_relative 'que/utils/transactions'
33
34
 
34
35
  require_relative 'que/version'
@@ -61,6 +62,7 @@ module Que
61
62
  include Utils::Logging
62
63
  include Utils::Middleware
63
64
  include Utils::QueueManagement
65
+ include Utils::Ruby2Keywords
64
66
  include Utils::Transactions
65
67
 
66
68
  extend Forwardable
data/que.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/que-rb/que'
14
14
  spec.license = 'MIT'
15
15
 
16
- spec.required_ruby_version = '< 3'
16
+ spec.required_ruby_version = '>= 2.7.0'
17
17
 
18
18
  files_to_exclude = [
19
19
  /\A\.circleci/,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: que
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-24 00:00:00.000000000 Z
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -34,6 +34,7 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - ".github/workflows/tests.yml"
36
36
  - ".gitignore"
37
+ - ".ruby-version"
37
38
  - CHANGELOG.md
38
39
  - Dockerfile
39
40
  - LICENSE.txt
@@ -71,6 +72,8 @@ files:
71
72
  - lib/que/migrations/4/up.sql
72
73
  - lib/que/migrations/5/down.sql
73
74
  - lib/que/migrations/5/up.sql
75
+ - lib/que/migrations/6/down.sql
76
+ - lib/que/migrations/6/up.sql
74
77
  - lib/que/poller.rb
75
78
  - lib/que/rails/railtie.rb
76
79
  - lib/que/result_queue.rb
@@ -84,6 +87,7 @@ files:
84
87
  - lib/que/utils/logging.rb
85
88
  - lib/que/utils/middleware.rb
86
89
  - lib/que/utils/queue_management.rb
90
+ - lib/que/utils/ruby2_keywords.rb
87
91
  - lib/que/utils/transactions.rb
88
92
  - lib/que/version.rb
89
93
  - lib/que/worker.rb
@@ -100,16 +104,16 @@ require_paths:
100
104
  - lib
101
105
  required_ruby_version: !ruby/object:Gem::Requirement
102
106
  requirements:
103
- - - "<"
107
+ - - ">="
104
108
  - !ruby/object:Gem::Version
105
- version: '3'
109
+ version: 2.7.0
106
110
  required_rubygems_version: !ruby/object:Gem::Requirement
107
111
  requirements:
108
- - - ">="
112
+ - - ">"
109
113
  - !ruby/object:Gem::Version
110
- version: '0'
114
+ version: 1.3.1
111
115
  requirements: []
112
- rubygems_version: 3.1.6
116
+ rubygems_version: 3.3.7
113
117
  signing_key:
114
118
  specification_version: 4
115
119
  summary: A PostgreSQL-based Job Queue