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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1301945308afd9596e1b563dd0ed568f8dd2bd82
4
- data.tar.gz: 770c8114bf9ef3bc84b96dcfb6a08fb251d77643
3
+ metadata.gz: '09e6812e437ea73062add603664517055b6eff54'
4
+ data.tar.gz: e7f001ecc56fc313c0af256c4bf5b89635318fad
5
5
  SHA512:
6
- metadata.gz: fdcd703b863c6e5ce2af7adeaf4a6205304d7c42ed0a227dc7d466c270294013efba20d7f2030c644663c6f6a6c98549b364802eeb407664e646056fa9d7adbe
7
- data.tar.gz: 408b96e763f411673b914011cb5f70dfde2b791da07a4487f3b018d5dad8ae1b1f01a83cc0a5cf182ec7852672dfadb97a46c92a34e0007e47aa22a5b6673b2f
6
+ metadata.gz: 14f6ac8a671ec1b6b13f9d24f4e3c13e844c37150ae50ca44c0b20d83590e2ff96173a83e225a63e9e613c6b4c479a2ec3e88e82ddbffa1c62a0817591958b89
7
+ data.tar.gz: f007a131aa6412f252e46316fdca1eb9a7895ad0eddbc9ae3a2ab0cbeaf8bc6a03ce7d7f5cfc665fe61a1b530858e52894ba7e72b1682d7a4decc7ca6db40872
@@ -1,3 +1,6 @@
1
+ ### 6.2.0
2
+ - Store SentTimestamp in SQLite and restore it on execution
3
+
1
4
  ### 6.1.0
2
5
  - Pass SQS message attributes through the middleware chain
3
6
  - Recover the SentTimestamp attribute and set it as queue start in Appsignal
@@ -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 sqewer_messages_v2 (
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 sqewer_messages_v2 (receipt_handle)")
35
- db.execute("CREATE INDEX IF NOT EXISTS on_queue_name ON sqewer_messages_v2 (queue_name)")
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
- messages = load_receipt_handles_and_bodies
44
- messages.map {|message| Message.new(message[0], message[1]) }
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 sqewer_messages_v2 WHERE queue_name = ?", @queue_name)
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 sqewer_messages_v2 WHERE receipt_handle = ?", id)
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 load_receipt_handles_and_bodies
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 sqewer_messages_v2
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 sqewer_messages_v2
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 sqewer_messages_v2
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 sqewer_messages_v2
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 |(_, *receipt_handle_and_body)|
133
- receipt_handle_and_body
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 sqewer_messages_v2
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
@@ -1,3 +1,3 @@
1
1
  module Sqewer
2
- VERSION = '6.1.0'
2
+ VERSION = '6.2.0'
3
3
  end
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.1.0
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-02 00:00:00.000000000 Z
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