riverqueue-sequel 0.13.0 → 0.15.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.
- checksums.yaml +4 -4
- data/lib/driver.rb +32 -12
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a3869013c8703e42675430a9ac21c77baf72994de9a8398c524ff080b09b374
|
|
4
|
+
data.tar.gz: 4282e30b7d4fe282f9600cf10b4ed86cb415930d861070d0bf4c80086e99827e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '081f77c7894c5ca3418c0ebb47d8c233b6a58554b2bfcec04aa7c89e901be347c3e69accb212749fa0f46854051544a68104c6816af397c45cd3efe232d4d4c9'
|
|
7
|
+
data.tar.gz: 21a5b271f12cbdedc4bf93803db4bab136ea35777cd101eb4723fd39b333a2dd54b81389c891017404d2f7c5b0c6bee929bff011b3f75cbd53eae35c996ad979
|
data/lib/driver.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require "securerandom"
|
|
4
4
|
|
|
5
5
|
module River::Driver
|
|
6
|
-
# Provides a Sequel driver for River supporting
|
|
6
|
+
# Provides a Sequel driver for River supporting Postgres, YugabyteDB, and SQLite.
|
|
7
7
|
#
|
|
8
8
|
# Used in conjunction with a River client like:
|
|
9
9
|
#
|
|
@@ -18,7 +18,7 @@ module River::Driver
|
|
|
18
18
|
class Sequel
|
|
19
19
|
include River::Driver::Runtime
|
|
20
20
|
|
|
21
|
-
# Creates a driver backed by a connected Sequel::Database for
|
|
21
|
+
# Creates a driver backed by a connected Sequel::Database for Postgres or
|
|
22
22
|
# SQLite.
|
|
23
23
|
def initialize(db)
|
|
24
24
|
@db = db
|
|
@@ -31,6 +31,16 @@ module River::Driver
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
# Runs the callback only if this transaction and its savepoints commit.
|
|
35
|
+
def after_commit(&block)
|
|
36
|
+
@db.after_commit(savepoint: true, &block)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Reports whether this thread has a transaction on the configured database.
|
|
40
|
+
def in_transaction?
|
|
41
|
+
@db.in_transaction?
|
|
42
|
+
end
|
|
43
|
+
|
|
34
44
|
def job_get_by_id(id)
|
|
35
45
|
if @is_sqlite
|
|
36
46
|
row = sqlite_job_rows("WHERE id = ? LIMIT 1", id).first
|
|
@@ -79,11 +89,13 @@ module River::Driver
|
|
|
79
89
|
end
|
|
80
90
|
end
|
|
81
91
|
|
|
82
|
-
# Runs the block in a Sequel transaction
|
|
83
|
-
#
|
|
92
|
+
# Runs the block in a Sequel transaction and returns the block's result.
|
|
93
|
+
# Joins an open transaction instead of opening a savepoint, unless that
|
|
94
|
+
# transaction uses Sequel's `auto_savepoint`.
|
|
84
95
|
def transaction
|
|
85
96
|
block_error = nil
|
|
86
|
-
|
|
97
|
+
options = runtime_legacy_subtransactions? ? {savepoint: true} : {}
|
|
98
|
+
@db.transaction(**options) do
|
|
87
99
|
yield
|
|
88
100
|
rescue ArgumentError => error
|
|
89
101
|
block_error = error
|
|
@@ -145,7 +157,7 @@ module River::Driver
|
|
|
145
157
|
private_constant :SQLITE_CONFLICT_WHERE, :SQLITE_JOB_COLUMNS, :UNIQUE_INSERT_METADATA_KEY
|
|
146
158
|
|
|
147
159
|
private def format_time(time)
|
|
148
|
-
time
|
|
160
|
+
normalize_time(time).strftime("%Y-%m-%d %H:%M:%S.%3N")
|
|
149
161
|
end
|
|
150
162
|
|
|
151
163
|
private def postgres_insert_params_to_hash(insert_params, nonce)
|
|
@@ -209,6 +221,15 @@ module River::Driver
|
|
|
209
221
|
end
|
|
210
222
|
end
|
|
211
223
|
|
|
224
|
+
private def runtime_notification_connection
|
|
225
|
+
params, schema = @db.synchronize do |connection|
|
|
226
|
+
[connection.conninfo_hash, connection.exec("SELECT current_schema()").getvalue(0, 0)]
|
|
227
|
+
end
|
|
228
|
+
params.compact!
|
|
229
|
+
params[:connect_timeout] = "5" unless params[:connect_timeout].to_i.positive?
|
|
230
|
+
[::PG.connect(params), schema]
|
|
231
|
+
end
|
|
232
|
+
|
|
212
233
|
private def runtime_postgres?
|
|
213
234
|
!@is_sqlite
|
|
214
235
|
end
|
|
@@ -221,17 +242,16 @@ module River::Driver
|
|
|
221
242
|
@db.literal(value)
|
|
222
243
|
end
|
|
223
244
|
|
|
224
|
-
private def runtime_unique_violation_class
|
|
225
|
-
::Sequel::UniqueConstraintViolation
|
|
226
|
-
end
|
|
227
|
-
|
|
228
245
|
private def runtime_value(row, key)
|
|
229
246
|
row[key] || row[key.to_s]
|
|
230
247
|
end
|
|
231
248
|
|
|
232
249
|
private def sqlite_insert_params_to_hash(insert_params, nonce)
|
|
233
250
|
{
|
|
234
|
-
args
|
|
251
|
+
# Embed the encoded args as a JSON string so they reach SQLite
|
|
252
|
+
# byte-for-byte. `json_extract` unwraps the string back to the
|
|
253
|
+
# encoded JSON text before `jsonb` parses it.
|
|
254
|
+
args: insert_params.encoded_args,
|
|
235
255
|
kind: insert_params.kind,
|
|
236
256
|
max_attempts: insert_params.max_attempts,
|
|
237
257
|
metadata: {UNIQUE_INSERT_METADATA_KEY => nonce},
|
|
@@ -250,7 +270,7 @@ module River::Driver
|
|
|
250
270
|
# matching migration 007 and newer River databases.
|
|
251
271
|
private def sqlite_job_insert_many(insert_params_array)
|
|
252
272
|
nonces = sqlite_insert_nonces(insert_params_array)
|
|
253
|
-
|
|
273
|
+
transaction do
|
|
254
274
|
jobs = insert_params_array.zip(nonces).map { |param, nonce| sqlite_insert_params_to_hash(param, nonce) }
|
|
255
275
|
inserted_nonces = nonces.to_h { |nonce| [nonce, true] }
|
|
256
276
|
|
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.
|
|
4
|
+
version: 0.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Blake Gentry
|
|
@@ -14,9 +14,9 @@ dependencies:
|
|
|
14
14
|
name: sequel
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '5.20'
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
22
|
version: '1000'
|
|
@@ -24,9 +24,9 @@ dependencies:
|
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
|
-
- - "
|
|
27
|
+
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '
|
|
29
|
+
version: '5.20'
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '1000'
|
|
@@ -36,15 +36,15 @@ dependencies:
|
|
|
36
36
|
requirements:
|
|
37
37
|
- - '='
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.
|
|
39
|
+
version: 0.15.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.
|
|
47
|
-
description: Sequel
|
|
46
|
+
version: 0.15.0
|
|
47
|
+
description: Sequel Postgres and SQLite driver for inserting and working River jobs
|
|
48
48
|
in Ruby.
|
|
49
49
|
email: brandur@brandur.org
|
|
50
50
|
executables: []
|
|
@@ -73,5 +73,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
73
|
requirements: []
|
|
74
74
|
rubygems_version: 4.0.9
|
|
75
75
|
specification_version: 4
|
|
76
|
-
summary: Sequel
|
|
76
|
+
summary: Sequel Postgres and SQLite driver for the River Ruby gem.
|
|
77
77
|
test_files: []
|