riverqueue-sequel 0.6.1 → 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 +101 -0
- metadata +4 -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
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
module River::Driver
|
2
|
+
# Provides a Sequel driver for River.
|
3
|
+
#
|
4
|
+
# Used in conjunction with a River client like:
|
5
|
+
#
|
6
|
+
# DB = Sequel.connect("postgres://...")
|
7
|
+
# client = River::Client.new(River::Driver::Sequel.new(DB))
|
8
|
+
#
|
9
|
+
class Sequel
|
10
|
+
def initialize(db)
|
11
|
+
@db = db
|
12
|
+
@db.extension(:pg_array)
|
13
|
+
@db.extension(:pg_json)
|
14
|
+
end
|
15
|
+
|
16
|
+
def job_get_by_id(id)
|
17
|
+
data_set = @db[:river_job].where(id: id)
|
18
|
+
data_set.first ? to_job_row(data_set.first) : nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def job_insert(insert_params)
|
22
|
+
job_insert_many([insert_params]).first
|
23
|
+
end
|
24
|
+
|
25
|
+
def job_insert_many(insert_params_array)
|
26
|
+
@db[:river_job]
|
27
|
+
.insert_conflict(
|
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
|
+
),
|
32
|
+
update: {kind: ::Sequel[:excluded][:kind]}
|
33
|
+
)
|
34
|
+
.returning(::Sequel.lit("*, (xmax != 0) AS unique_skipped_as_duplicate"))
|
35
|
+
.multi_insert(insert_params_array.map { |p| insert_params_to_hash(p) })
|
36
|
+
.map { |row| to_insert_result(row) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def job_list
|
40
|
+
data_set = @db[:river_job].order_by(:id)
|
41
|
+
data_set.all.map { |job| to_job_row(job) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def rollback_exception
|
45
|
+
::Sequel::Rollback
|
46
|
+
end
|
47
|
+
|
48
|
+
def transaction(&)
|
49
|
+
@db.transaction(savepoint: true, &)
|
50
|
+
end
|
51
|
+
|
52
|
+
private def insert_params_to_hash(insert_params)
|
53
|
+
{
|
54
|
+
args: insert_params.encoded_args,
|
55
|
+
kind: insert_params.kind,
|
56
|
+
max_attempts: insert_params.max_attempts,
|
57
|
+
priority: insert_params.priority,
|
58
|
+
queue: insert_params.queue,
|
59
|
+
state: insert_params.state,
|
60
|
+
scheduled_at: insert_params.scheduled_at,
|
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]]
|
69
|
+
end
|
70
|
+
|
71
|
+
private def to_job_row(river_job)
|
72
|
+
River::JobRow.new(
|
73
|
+
id: river_job[:id],
|
74
|
+
args: river_job[:args].to_h,
|
75
|
+
attempt: river_job[:attempt],
|
76
|
+
attempted_at: river_job[:attempted_at]&.getutc,
|
77
|
+
attempted_by: river_job[:attempted_by],
|
78
|
+
created_at: river_job[:created_at].getutc,
|
79
|
+
errors: river_job[:errors]&.map { |deserialized_error|
|
80
|
+
River::AttemptError.new(
|
81
|
+
at: Time.parse(deserialized_error["at"]),
|
82
|
+
attempt: deserialized_error["attempt"],
|
83
|
+
error: deserialized_error["error"],
|
84
|
+
trace: deserialized_error["trace"]
|
85
|
+
)
|
86
|
+
},
|
87
|
+
finalized_at: river_job[:finalized_at]&.getutc,
|
88
|
+
kind: river_job[:kind],
|
89
|
+
max_attempts: river_job[:max_attempts],
|
90
|
+
metadata: river_job[:metadata],
|
91
|
+
priority: river_job[:priority],
|
92
|
+
queue: river_job[:queue],
|
93
|
+
scheduled_at: river_job[:scheduled_at].getutc,
|
94
|
+
state: river_job[:state],
|
95
|
+
tags: river_job[:tags].to_a,
|
96
|
+
unique_key: river_job[:unique_key]&.to_s,
|
97
|
+
unique_states: ::River::UniqueBitmask.to_states(river_job[:unique_states]&.to_i(2))
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
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
|
@@ -58,6 +58,7 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- lib/driver.rb
|
61
62
|
- lib/riverqueue-sequel.rb
|
62
63
|
homepage: https://riverqueue.com
|
63
64
|
licenses:
|
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
+
rubygems_version: 3.5.16
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: Sequel driver for the River Ruby gem.
|