riverqueue-sequel 0.15.0 → 0.16.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/driver.rb +59 -55
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a3869013c8703e42675430a9ac21c77baf72994de9a8398c524ff080b09b374
4
- data.tar.gz: 4282e30b7d4fe282f9600cf10b4ed86cb415930d861070d0bf4c80086e99827e
3
+ metadata.gz: 9722dd3b91092e1f94fa96e670da71802536f4d8c8dc4046d634ad0b7409ca4c
4
+ data.tar.gz: 0afa80638811c56462b40c1660b5dad2a8affdcbe60b872eddd6b40148fe5d85
5
5
  SHA512:
6
- metadata.gz: '081f77c7894c5ca3418c0ebb47d8c233b6a58554b2bfcec04aa7c89e901be347c3e69accb212749fa0f46854051544a68104c6816af397c45cd3efe232d4d4c9'
7
- data.tar.gz: 21a5b271f12cbdedc4bf93803db4bab136ea35777cd101eb4723fd39b333a2dd54b81389c891017404d2f7c5b0c6bee929bff011b3f75cbd53eae35c996ad979
6
+ metadata.gz: c83a4915de0f037bfa54a0224583b5f2f7e0381ad016382def5fe933c82a6426519267e7175b8c88a361b87a96ec1d53d82574a0c41bf4685192f5fd6166afd2
7
+ data.tar.gz: 6a72d66800b17083e7e20d4a0f06b69654a9b3e69166b80d2b1fde8c649505f6c8277dc284e8b5f1bd8921006ad7274806dddddd79b7b613901b1c6aff281b94
data/lib/driver.rb CHANGED
@@ -58,12 +58,14 @@ module River::Driver
58
58
  def job_insert_many(insert_params_array)
59
59
  return [] if insert_params_array.empty?
60
60
 
61
- return sqlite_job_insert_many(insert_params_array) if @is_sqlite
62
-
63
- transaction do
64
- results = postgres_job_insert_many(insert_params_array)
65
- postgres_notify_insert(insert_params_array)
66
- results
61
+ runtime_insert_transaction(insert_params_array) do
62
+ if @is_sqlite
63
+ sqlite_job_insert_many(insert_params_array)
64
+ else
65
+ results = postgres_job_insert_many(insert_params_array)
66
+ postgres_notify_insert(insert_params_array)
67
+ results
68
+ end
67
69
  end
68
70
  end
69
71
 
@@ -209,6 +211,10 @@ module River::Driver
209
211
  @db.run(sql)
210
212
  end
211
213
 
214
+ private def runtime_job_columns
215
+ @is_sqlite ? SQLITE_JOB_COLUMNS : "*"
216
+ end
217
+
212
218
  private def runtime_job_list_without_params
213
219
  job_list(:all)
214
220
  end
@@ -270,55 +276,53 @@ module River::Driver
270
276
  # matching migration 007 and newer River databases.
271
277
  private def sqlite_job_insert_many(insert_params_array)
272
278
  nonces = sqlite_insert_nonces(insert_params_array)
273
- transaction do
274
- jobs = insert_params_array.zip(nonces).map { |param, nonce| sqlite_insert_params_to_hash(param, nonce) }
275
- inserted_nonces = nonces.to_h { |nonce| [nonce, true] }
276
-
277
- sql = <<~SQL
278
- INSERT INTO river_job (
279
- args,
280
- created_at,
281
- kind,
282
- max_attempts,
283
- metadata,
284
- priority,
285
- queue,
286
- scheduled_at,
287
- state,
288
- tags,
289
- unique_key,
290
- unique_states
291
- )
292
- SELECT
293
- jsonb(json_extract(value, '$.args')),
294
- datetime('now', 'subsec'),
295
- cast(json_extract(value, '$.kind') AS text),
296
- cast(json_extract(value, '$.max_attempts') AS integer),
297
- jsonb(json_extract(value, '$.metadata')),
298
- cast(json_extract(value, '$.priority') AS integer),
299
- cast(json_extract(value, '$.queue') AS text),
300
- coalesce(cast(json_extract(value, '$.scheduled_at') AS text), datetime('now', 'subsec')),
301
- cast(json_extract(value, '$.state') AS text),
302
- jsonb(json_extract(value, '$.tags')),
303
- CASE
304
- WHEN length(cast(json_extract(value, '$.unique_key') AS text)) = 0 THEN NULL
305
- ELSE unhex(cast(json_extract(value, '$.unique_key') AS text))
306
- END,
307
- nullif(cast(json_extract(value, '$.unique_states') AS integer), 0)
308
- FROM json_each(cast(? AS blob))
309
- WHERE true
310
- ON CONFLICT (unique_key) WHERE #{SQLITE_CONFLICT_WHERE}
311
- DO UPDATE SET kind = river_job.kind
312
- RETURNING #{SQLITE_JOB_COLUMNS}
313
- SQL
314
-
315
- rows = @db.fetch(sql, JSON.generate(jobs)).all
316
- sqlite_notify_insert(insert_params_array)
317
-
318
- rows.map do |row|
319
- metadata = JSON.parse(row[:metadata])
320
- [sqlite_to_job_row_from_raw(row), !inserted_nonces.key?(metadata[UNIQUE_INSERT_METADATA_KEY])]
321
- end
279
+ jobs = insert_params_array.zip(nonces).map { |param, nonce| sqlite_insert_params_to_hash(param, nonce) }
280
+ inserted_nonces = nonces.to_h { |nonce| [nonce, true] }
281
+
282
+ sql = <<~SQL
283
+ INSERT INTO river_job (
284
+ args,
285
+ created_at,
286
+ kind,
287
+ max_attempts,
288
+ metadata,
289
+ priority,
290
+ queue,
291
+ scheduled_at,
292
+ state,
293
+ tags,
294
+ unique_key,
295
+ unique_states
296
+ )
297
+ SELECT
298
+ jsonb(json_extract(value, '$.args')),
299
+ datetime('now', 'subsec'),
300
+ cast(json_extract(value, '$.kind') AS text),
301
+ cast(json_extract(value, '$.max_attempts') AS integer),
302
+ jsonb(json_extract(value, '$.metadata')),
303
+ cast(json_extract(value, '$.priority') AS integer),
304
+ cast(json_extract(value, '$.queue') AS text),
305
+ coalesce(cast(json_extract(value, '$.scheduled_at') AS text), datetime('now', 'subsec')),
306
+ cast(json_extract(value, '$.state') AS text),
307
+ jsonb(json_extract(value, '$.tags')),
308
+ CASE
309
+ WHEN length(cast(json_extract(value, '$.unique_key') AS text)) = 0 THEN NULL
310
+ ELSE unhex(cast(json_extract(value, '$.unique_key') AS text))
311
+ END,
312
+ nullif(cast(json_extract(value, '$.unique_states') AS integer), 0)
313
+ FROM json_each(cast(? AS blob))
314
+ WHERE true
315
+ ON CONFLICT (unique_key) WHERE #{SQLITE_CONFLICT_WHERE}
316
+ DO UPDATE SET kind = river_job.kind
317
+ RETURNING #{SQLITE_JOB_COLUMNS}
318
+ SQL
319
+
320
+ rows = @db.fetch(sql, JSON.generate(jobs)).all
321
+ sqlite_notify_insert(insert_params_array)
322
+
323
+ rows.map do |row|
324
+ job = sqlite_to_job_row_from_raw(row)
325
+ [job, !inserted_nonces.key?(job.metadata[UNIQUE_INSERT_METADATA_KEY])]
322
326
  end
323
327
  end
324
328
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riverqueue-sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Gentry
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.15.0
39
+ version: 0.16.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.15.0
46
+ version: 0.16.0
47
47
  description: Sequel Postgres and SQLite driver for inserting and working River jobs
48
48
  in Ruby.
49
49
  email: brandur@brandur.org