dirty_pipeline 0.8.1 → 0.8.2
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/dirty_pipeline.rb +8 -0
- data/lib/dirty_pipeline/pg/queue.rb +10 -14
- data/lib/dirty_pipeline/pg/railway.rb +18 -14
- data/lib/dirty_pipeline/pg/storage.rb +13 -11
- data/lib/dirty_pipeline/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30736e6846e314622b7be4b807e6d7c6c4adddec24619d4d6cc13c5e88dc38d5
|
4
|
+
data.tar.gz: 30fde8fe371d9140d8b12f937205cf099df36399fbcc2f4d7b17a5bc8faa5385
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fccab6567a59465c945f3d2ecf82dd960e813d24defb690fee1da40d35ea0935ce3d3f47d6fb4838581c45ce527ce9502c17c812cb01d3bdf357dd9e2cdb5361
|
7
|
+
data.tar.gz: 9349d42d38f1c3c7e92b523901466859d0fd1d717e9c40d37f29237a4aa52024102d128aac83fbb8745f6a534fff38ea8409d95ca81caea251d3d211a179cd4b
|
data/lib/dirty_pipeline.rb
CHANGED
@@ -32,6 +32,14 @@ module DirtyPipeline
|
|
32
32
|
fail NotImplementedError
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.with_postgres_transaction
|
36
|
+
with_postgres do |conn|
|
37
|
+
conn.transaction do |transaction_conn|
|
38
|
+
yield transaction_conn
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
# def self.with_postgres
|
36
44
|
# yield(ActiveRecord::Base.connection.raw_connection)
|
37
45
|
# ensure
|
@@ -47,9 +47,9 @@ module DirtyPipeline
|
|
47
47
|
|
48
48
|
def clear!
|
49
49
|
with_postgres do |c|
|
50
|
-
c.transaction do
|
51
|
-
|
52
|
-
|
50
|
+
c.transaction do |tc|
|
51
|
+
tc.exec(DELETE_ACTIVE, [active_event_key])
|
52
|
+
tc.exec(DELETE_EVENTS, [events_queue_key])
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -71,9 +71,7 @@ module DirtyPipeline
|
|
71
71
|
SQL
|
72
72
|
def push(event)
|
73
73
|
with_postgres do |c|
|
74
|
-
c.
|
75
|
-
c.exec(PUSH_EVENT, [events_queue_key, pack(event)])
|
76
|
-
end
|
74
|
+
c.exec(PUSH_EVENT, [events_queue_key, pack(event)])
|
77
75
|
end
|
78
76
|
|
79
77
|
self
|
@@ -85,9 +83,7 @@ module DirtyPipeline
|
|
85
83
|
SQL
|
86
84
|
def unshift(event)
|
87
85
|
with_postgres do |c|
|
88
|
-
c.
|
89
|
-
c.exec(UNSHIFT_EVENT, [events_queue_key, pack(event)])
|
90
|
-
end
|
86
|
+
c.exec(UNSHIFT_EVENT, [events_queue_key, pack(event)])
|
91
87
|
end
|
92
88
|
self
|
93
89
|
end
|
@@ -109,14 +105,14 @@ module DirtyPipeline
|
|
109
105
|
SQL
|
110
106
|
def pop
|
111
107
|
with_postgres do |c|
|
112
|
-
c.transaction do
|
108
|
+
c.transaction do |tc|
|
113
109
|
event_id, raw_event =
|
114
|
-
PG.multi(
|
110
|
+
PG.multi(tc.exec(SELECT_LAST_EVENT, [events_queue_key]))
|
115
111
|
if raw_event.nil?
|
116
|
-
|
112
|
+
tc.exec(DELETE_ACTIVE_EVENT, [active_event_key])
|
117
113
|
else
|
118
|
-
|
119
|
-
|
114
|
+
tc.exec(DELETE_EVENT, [events_queue_key, event_id])
|
115
|
+
tc.exec(SET_EVENT_ACTIVE, [active_event_key, raw_event])
|
120
116
|
end
|
121
117
|
unpack(raw_event)
|
122
118
|
end
|
@@ -37,6 +37,10 @@ module DirtyPipeline
|
|
37
37
|
]
|
38
38
|
end
|
39
39
|
|
40
|
+
def with_postgres(&block)
|
41
|
+
DirtyPipeline.with_postgres(&block)
|
42
|
+
end
|
43
|
+
|
40
44
|
DELETE_OPERATION = <<~SQL
|
41
45
|
DELETE FROM dp_active_operations WHERE key = $1;
|
42
46
|
SQL
|
@@ -45,10 +49,10 @@ module DirtyPipeline
|
|
45
49
|
SQL
|
46
50
|
def clear!
|
47
51
|
@queues.values.each(&:clear!)
|
48
|
-
|
49
|
-
c.transaction do
|
50
|
-
|
51
|
-
|
52
|
+
with_postgres do |c|
|
53
|
+
c.transaction do |tc|
|
54
|
+
tc.exec DELETE_OPERATION, [active_operation_key]
|
55
|
+
tc.exec DELETE_TRANSACTION, [active_transaction_key]
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
@@ -76,10 +80,10 @@ module DirtyPipeline
|
|
76
80
|
raise ArgumentError unless DEFAULT_OPERATIONS.include?(name.to_s)
|
77
81
|
return if name.to_s == active
|
78
82
|
|
79
|
-
|
80
|
-
c.
|
81
|
-
|
82
|
-
|
83
|
+
with_postgres do |c|
|
84
|
+
c.exec('START TRANSACTION;')
|
85
|
+
c.exec(SWITCH_OPERATION, [active_operation_key, name])
|
86
|
+
c.exec('COMMIT;')
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
@@ -87,7 +91,7 @@ module DirtyPipeline
|
|
87
91
|
SELECT name FROM dp_active_operations WHERE key = $1;
|
88
92
|
SQL
|
89
93
|
def active
|
90
|
-
|
94
|
+
with_postgres do |c|
|
91
95
|
PG.single c.exec(SELECT_OPERATION, [active_operation_key])
|
92
96
|
end
|
93
97
|
end
|
@@ -97,7 +101,7 @@ module DirtyPipeline
|
|
97
101
|
SELECT name FROM dp_active_transactions WHERE key = $1;
|
98
102
|
SQL
|
99
103
|
def running_transaction
|
100
|
-
|
104
|
+
with_postgres do |c|
|
101
105
|
PG.single c.exec(SELECT_TRANSACTION, [active_transaction_key])
|
102
106
|
end
|
103
107
|
end
|
@@ -128,10 +132,10 @@ module DirtyPipeline
|
|
128
132
|
SQL
|
129
133
|
def start_transaction!
|
130
134
|
switch_to(DEFAULT_OPERATIONS.first) unless active
|
131
|
-
|
132
|
-
c.
|
133
|
-
|
134
|
-
|
135
|
+
with_postgres do |c|
|
136
|
+
c.exec('START TRANSACTION;')
|
137
|
+
c.exec(SWITCH_TRANSACTION, [active_transaction_key, @tx_id])
|
138
|
+
c.exec('COMMIT;')
|
135
139
|
end
|
136
140
|
end
|
137
141
|
|
@@ -39,6 +39,10 @@ module DirtyPipeline
|
|
39
39
|
raise InvalidPipelineStorage, store unless valid_store?
|
40
40
|
end
|
41
41
|
|
42
|
+
def with_postgres(&block)
|
43
|
+
DirtyPipeline.with_postgres(&block)
|
44
|
+
end
|
45
|
+
|
42
46
|
def reset!
|
43
47
|
reset
|
44
48
|
save!
|
@@ -57,16 +61,14 @@ module DirtyPipeline
|
|
57
61
|
def commit!(event)
|
58
62
|
store["status"] = event.destination if event.destination
|
59
63
|
store["state"].merge!(event.changes) unless event.changes.to_h.empty?
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
c.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
)
|
69
|
-
end
|
64
|
+
data, error = {}, {}
|
65
|
+
data = event.data.to_h if event.data.respond_to?(:to_h)
|
66
|
+
error = event.error.to_h if event.error.respond_to?(:to_h)
|
67
|
+
with_postgres do |c|
|
68
|
+
c.exec(
|
69
|
+
SAVE_EVENT,
|
70
|
+
[event.id, subject_key, JSON.dump(data), JSON.dump(error)]
|
71
|
+
)
|
70
72
|
end
|
71
73
|
save!
|
72
74
|
end
|
@@ -76,7 +78,7 @@ module DirtyPipeline
|
|
76
78
|
WHERE uuid = $1 AND context = $2;
|
77
79
|
SQL
|
78
80
|
def find_event(event_id)
|
79
|
-
|
81
|
+
with_postgres do |c|
|
80
82
|
found_event, found_error =
|
81
83
|
PG.multi(c.exec(FIND_EVENT, [event_id, subject_key]))
|
82
84
|
return unless found_event
|