sqewer 6.1.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/sqewer/extensions/appsignal_wrapper.rb +2 -2
- data/lib/sqewer/local_connection.rb +25 -21
- data/lib/sqewer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09e6812e437ea73062add603664517055b6eff54'
|
4
|
+
data.tar.gz: e7f001ecc56fc313c0af256c4bf5b89635318fad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14f6ac8a671ec1b6b13f9d24f4e3c13e844c37150ae50ca44c0b20d83590e2ff96173a83e225a63e9e613c6b4c479a2ec3e88e82ddbffa1c62a0817591958b89
|
7
|
+
data.tar.gz: f007a131aa6412f252e46316fdca1eb9a7895ad0eddbc9ae3a2ab0cbeaf8bc6a03ce7d7f5cfc665fe61a1b530858e52894ba7e72b1682d7a4decc7ca6db40872
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@ module Sqewer
|
|
4
4
|
# to Appsignal and to monitor performance. Will only activate
|
5
5
|
# if the Appsignal gem is loaded within the current process and active.
|
6
6
|
class AppsignalWrapper
|
7
|
-
|
7
|
+
|
8
8
|
def self.new
|
9
9
|
if defined?(Appsignal)
|
10
10
|
super
|
@@ -15,7 +15,7 @@ module Sqewer
|
|
15
15
|
|
16
16
|
# extend Appsignal::Hooks::Helpers
|
17
17
|
# and use format_args(args) on the jobargs?
|
18
|
-
|
18
|
+
|
19
19
|
# Acts as a replacement for Appsignal::GenericRequest
|
20
20
|
class FakeRequest < Struct.new(:params)
|
21
21
|
def initialize; super({}); end
|
@@ -21,7 +21,7 @@ class Sqewer::LocalConnection < Sqewer::Connection
|
|
21
21
|
require 'sqlite3'
|
22
22
|
@db_path, @queue_name = self.class.parse_queue_url(queue_url_with_sqlite3_scheme)
|
23
23
|
with_db do |db|
|
24
|
-
db.execute("CREATE TABLE IF NOT EXISTS
|
24
|
+
db.execute("CREATE TABLE IF NOT EXISTS sqewer_messages_v3 (
|
25
25
|
id INTEGER PRIMARY KEY AUTOINCREMENT ,
|
26
26
|
queue_name VARCHAR NOT NULL,
|
27
27
|
receipt_handle VARCHAR NOT NULL,
|
@@ -29,19 +29,21 @@ class Sqewer::LocalConnection < Sqewer::Connection
|
|
29
29
|
times_delivered_so_far INTEGER DEFAULT 0,
|
30
30
|
last_delivery_at_epoch INTEGER,
|
31
31
|
visible BOOLEAN DEFAULT 't',
|
32
|
+
sent_timestamp_millis INTEGER,
|
32
33
|
message_body TEXT)"
|
33
34
|
)
|
34
|
-
db.execute("CREATE INDEX IF NOT EXISTS on_receipt_handle ON
|
35
|
-
db.execute("CREATE INDEX IF NOT EXISTS on_queue_name ON
|
35
|
+
db.execute("CREATE INDEX IF NOT EXISTS on_receipt_handle ON sqewer_messages_v3 (receipt_handle)")
|
36
|
+
db.execute("CREATE INDEX IF NOT EXISTS on_queue_name ON sqewer_messages_v3 (queue_name)")
|
36
37
|
end
|
37
38
|
rescue LoadError => e
|
38
39
|
raise e, "You need the sqlite3 gem in your Gemfile to use LocalConnection. Add it to your Gemfile (`gem 'sqlite3'')"
|
39
40
|
end
|
40
41
|
|
41
|
-
# @return [Array<Message>] an array of Message objects
|
42
|
+
# @return [Array<Message>] an array of Message objects
|
42
43
|
def receive_messages
|
43
|
-
|
44
|
-
|
44
|
+
load_receipt_handles_bodies_and_timestamps.map do |(receipt_handle, message_body, sent_timestamp_millis)|
|
45
|
+
Message.new(receipt_handle, message_body, {'SentTimestamp' => sent_timestamp_millis})
|
46
|
+
end
|
45
47
|
end
|
46
48
|
|
47
49
|
# @yield [#send_message] the object you can send messages through (will be flushed at method return)
|
@@ -66,7 +68,7 @@ class Sqewer::LocalConnection < Sqewer::Connection
|
|
66
68
|
# Only gets used in tests
|
67
69
|
def truncate!
|
68
70
|
with_db do |db|
|
69
|
-
db.execute("DELETE FROM
|
71
|
+
db.execute("DELETE FROM sqewer_messages_v3 WHERE queue_name = ?", @queue_name)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
@@ -91,51 +93,53 @@ class Sqewer::LocalConnection < Sqewer::Connection
|
|
91
93
|
with_db do |db|
|
92
94
|
db.execute("BEGIN")
|
93
95
|
ids_to_delete.each do |id|
|
94
|
-
db.execute("DELETE FROM
|
96
|
+
db.execute("DELETE FROM sqewer_messages_v3 WHERE receipt_handle = ?", id)
|
95
97
|
end
|
96
98
|
db.execute("COMMIT")
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
|
-
def
|
102
|
+
def load_receipt_handles_bodies_and_timestamps
|
101
103
|
t = Time.now.to_i
|
102
104
|
|
103
105
|
# First make messages that were previously marked invisible but not deleted visible again
|
104
106
|
with_db do |db|
|
105
107
|
db.execute("BEGIN")
|
106
108
|
# Make messages visible that have to be redelivered
|
107
|
-
db.execute("UPDATE
|
108
|
-
SET visible = 't'
|
109
|
+
db.execute("UPDATE sqewer_messages_v3
|
110
|
+
SET visible = 't'
|
109
111
|
WHERE queue_name = ? AND visible = 'f' AND last_delivery_at_epoch < ?", @queue_name.to_s, t - 60)
|
110
112
|
# Remove hopeless messages
|
111
|
-
db.execute("DELETE FROM
|
113
|
+
db.execute("DELETE FROM sqewer_messages_v3
|
112
114
|
WHERE queue_name = ? AND times_delivered_so_far >= ?", @queue_name.to_s, ASSUME_DEADLETTER_AFTER_N_DELIVERIES)
|
113
115
|
db.execute("COMMIT")
|
114
116
|
end
|
115
117
|
|
118
|
+
# Then select messages to receive
|
116
119
|
rows = with_readonly_db do |db|
|
117
|
-
db.execute("SELECT id, receipt_handle, message_body FROM
|
120
|
+
db.execute("SELECT id, receipt_handle, message_body, sent_timestamp_millis FROM sqewer_messages_v3
|
118
121
|
WHERE queue_name = ? AND visible = 't' AND deliver_after_epoch <= ? AND last_delivery_at_epoch <= ?",
|
119
122
|
@queue_name.to_s, t, t)
|
120
123
|
end
|
121
|
-
|
124
|
+
|
122
125
|
with_db do |db|
|
123
126
|
db.execute("BEGIN")
|
124
127
|
rows.map do |(id, *_)|
|
125
|
-
db.execute("UPDATE
|
128
|
+
db.execute("UPDATE sqewer_messages_v3
|
126
129
|
SET visible = 'f', times_delivered_so_far = times_delivered_so_far + 1, last_delivery_at_epoch = ?
|
127
130
|
WHERE id = ?", t, id)
|
128
131
|
end
|
129
132
|
db.execute("COMMIT")
|
130
133
|
end
|
131
134
|
|
132
|
-
rows.map do |(
|
133
|
-
|
135
|
+
rows.map do |(_db_id, receipt_handle, body, timestamp)|
|
136
|
+
[receipt_handle, body, timestamp]
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
137
140
|
def persist_messages(messages)
|
138
141
|
epoch = Time.now.to_i
|
142
|
+
sent_timestamp_millis = (Time.now.to_f * 1000).to_i
|
139
143
|
bodies_and_deliver_afters = messages.map do |msg|
|
140
144
|
[msg.fetch(:message_body), epoch + msg.fetch(:delay_seconds, 0)]
|
141
145
|
end
|
@@ -143,10 +147,10 @@ class Sqewer::LocalConnection < Sqewer::Connection
|
|
143
147
|
with_db do |db|
|
144
148
|
db.execute("BEGIN")
|
145
149
|
bodies_and_deliver_afters.map do |body, deliver_after_epoch|
|
146
|
-
db.execute("INSERT INTO
|
147
|
-
(queue_name, receipt_handle, message_body, deliver_after_epoch, last_delivery_at_epoch)
|
148
|
-
VALUES(?, ?, ?, ?, ?)",
|
149
|
-
@queue_name.to_s, SecureRandom.uuid, body, deliver_after_epoch, epoch)
|
150
|
+
db.execute("INSERT INTO sqewer_messages_v3
|
151
|
+
(queue_name, receipt_handle, message_body, deliver_after_epoch, last_delivery_at_epoch, sent_timestamp_millis)
|
152
|
+
VALUES(?, ?, ?, ?, ?, ?)",
|
153
|
+
@queue_name.to_s, SecureRandom.uuid, body, deliver_after_epoch, epoch, sent_timestamp_millis)
|
150
154
|
end
|
151
155
|
db.execute("COMMIT")
|
152
156
|
end
|
data/lib/sqewer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqewer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-sqs
|