riverqueue-sequel 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/driver.rb +19 -38
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcba38bb9184685170e02a42f53ef69efa47ef25c364cfa6047d7ed7b457ee01
|
4
|
+
data.tar.gz: 95e6cc145f3faa7632a3ab8e25d0896537d54a34756ec0b246028cf736e47086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 416b64b2e91fadf29ed0b30814556dcaae74671ed74165586330518c9f4622fb40c13ed4c35cce7cb9b6d8089be9d8cb3f310b329e0682efa864e6380288d6e5
|
7
|
+
data.tar.gz: 45ae9a7abbf4d15e0c7f2cd5cbc9974446f5ee0da6d3718aa679e668a2f52b8164e7c1176ab1c21637896f5922afde189aed0b567fba147e2fecb8b887029e92
|
data/lib/driver.rb
CHANGED
@@ -13,51 +13,27 @@ module River::Driver
|
|
13
13
|
@db.extension(:pg_json)
|
14
14
|
end
|
15
15
|
|
16
|
-
def advisory_lock(key)
|
17
|
-
@db.fetch("SELECT pg_advisory_xact_lock(?)", key).first
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def advisory_lock_try(key)
|
22
|
-
@db.fetch("SELECT pg_try_advisory_xact_lock(?)", key).first[:pg_try_advisory_xact_lock]
|
23
|
-
end
|
24
|
-
|
25
16
|
def job_get_by_id(id)
|
26
17
|
data_set = @db[:river_job].where(id: id)
|
27
18
|
data_set.first ? to_job_row(data_set.first) : nil
|
28
19
|
end
|
29
20
|
|
30
|
-
def job_get_by_kind_and_unique_properties(get_params)
|
31
|
-
data_set = @db[:river_job].where(kind: get_params.kind)
|
32
|
-
data_set = data_set.where(::Sequel.lit("tstzrange(?, ?, '[)') @> created_at", get_params.created_at[0], get_params.created_at[1])) if get_params.created_at
|
33
|
-
data_set = data_set.where(args: get_params.encoded_args) if get_params.encoded_args
|
34
|
-
data_set = data_set.where(queue: get_params.queue) if get_params.queue
|
35
|
-
data_set = data_set.where(state: get_params.state) if get_params.state
|
36
|
-
data_set.first ? to_job_row(data_set.first) : nil
|
37
|
-
end
|
38
|
-
|
39
21
|
def job_insert(insert_params)
|
40
|
-
|
22
|
+
job_insert_many([insert_params]).first
|
41
23
|
end
|
42
24
|
|
43
|
-
def
|
44
|
-
|
25
|
+
def job_insert_many(insert_params_array)
|
26
|
+
@db[:river_job]
|
45
27
|
.insert_conflict(
|
46
|
-
target: [:
|
47
|
-
conflict_where: ::Sequel.lit(
|
28
|
+
target: [:unique_key],
|
29
|
+
conflict_where: ::Sequel.lit(
|
30
|
+
"unique_key IS NOT NULL AND unique_states IS NOT NULL AND river_job_state_in_bitmask(unique_states, state)"
|
31
|
+
),
|
48
32
|
update: {kind: ::Sequel[:excluded][:kind]}
|
49
33
|
)
|
50
34
|
.returning(::Sequel.lit("*, (xmax != 0) AS unique_skipped_as_duplicate"))
|
51
|
-
.
|
52
|
-
|
53
|
-
)
|
54
|
-
|
55
|
-
[to_job_row(values), values[:unique_skipped_as_duplicate]]
|
56
|
-
end
|
57
|
-
|
58
|
-
def job_insert_many(insert_params_many)
|
59
|
-
@db[:river_job].multi_insert(insert_params_many.map { |p| insert_params_to_hash(p) })
|
60
|
-
insert_params_many.count
|
35
|
+
.multi_insert(insert_params_array.map { |p| insert_params_to_hash(p) })
|
36
|
+
.map { |row| to_insert_result(row) }
|
61
37
|
end
|
62
38
|
|
63
39
|
def job_list
|
@@ -74,8 +50,6 @@ module River::Driver
|
|
74
50
|
end
|
75
51
|
|
76
52
|
private def insert_params_to_hash(insert_params)
|
77
|
-
# the call to `#compact` is important so that we remove nils and table
|
78
|
-
# default values get picked up instead
|
79
53
|
{
|
80
54
|
args: insert_params.encoded_args,
|
81
55
|
kind: insert_params.kind,
|
@@ -84,8 +58,14 @@ module River::Driver
|
|
84
58
|
queue: insert_params.queue,
|
85
59
|
state: insert_params.state,
|
86
60
|
scheduled_at: insert_params.scheduled_at,
|
87
|
-
tags:
|
88
|
-
|
61
|
+
tags: ::Sequel.pg_array(insert_params.tags || [], :text),
|
62
|
+
unique_key: insert_params.unique_key ? ::Sequel.blob(insert_params.unique_key) : nil,
|
63
|
+
unique_states: insert_params.unique_states
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
private def to_insert_result(result)
|
68
|
+
[to_job_row(result), result[:unique_skipped_as_duplicate]]
|
89
69
|
end
|
90
70
|
|
91
71
|
private def to_job_row(river_job)
|
@@ -113,7 +93,8 @@ module River::Driver
|
|
113
93
|
scheduled_at: river_job[:scheduled_at].getutc,
|
114
94
|
state: river_job[:state],
|
115
95
|
tags: river_job[:tags].to_a,
|
116
|
-
unique_key: river_job[:unique_key]&.to_s
|
96
|
+
unique_key: river_job[:unique_key]&.to_s,
|
97
|
+
unique_states: ::River::UniqueBitmask.to_states(river_job[:unique_states]&.to_i(2))
|
117
98
|
)
|
118
99
|
end
|
119
100
|
end
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Gentry
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
82
|
+
rubygems_version: 3.5.16
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Sequel driver for the River Ruby gem.
|