postqueue 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postqueue/cli/stats.rb +29 -0
- data/lib/postqueue/cli.rb +3 -4
- data/lib/postqueue/queue/callback.rb +0 -2
- data/lib/postqueue/queue/runner.rb +11 -10
- data/lib/postqueue/queue/select_and_lock.rb +11 -6
- data/lib/postqueue/queue.rb +1 -1
- data/lib/postqueue/version.rb +1 -1
- data/spec/postqueue/concurrency_spec.rb +4 -7
- data/spec/postqueue/process_errors_spec.rb +3 -1
- data/spec/postqueue/process_spec.rb +0 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2edb04093f702ef2fb42d716de3ebdc71c9a65f3
|
4
|
+
data.tar.gz: f2148b265f5669b0b8a81610d1b355d7e8a9036e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b2a2098f86dfa48039e57e3c61d7491c22f19cb0e016af0af0e055d561dc0ff91605e0b3b2a4ae3c5f16acda96aa4e606a8fb4a9d326e97740bca50f2e5a615
|
7
|
+
data.tar.gz: 9bb0c84cb618a457d5410ef7c2337035ffe15573085940011730165a2b1791b5f05f4a2bf8ca766ea879d7a6d68ebe00e179147ba3fc7ac5247647363dc813a9
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module Postqueue
|
4
|
+
module CLI
|
5
|
+
module Stats
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def stats(_options)
|
9
|
+
require "table_print"
|
10
|
+
sql = <<-SQL
|
11
|
+
SELECT op,
|
12
|
+
COUNT(*) AS count,
|
13
|
+
MIN(now() - created_at) AS min_age,
|
14
|
+
MAX(now() - created_at) AS max_age,
|
15
|
+
AVG(now() - created_at) AS avg_age
|
16
|
+
FROM #{Postqueue.item_class.table_name} GROUP BY op
|
17
|
+
SQL
|
18
|
+
|
19
|
+
recs = Postqueue.item_class.find_by_sql(sql)
|
20
|
+
tp recs, :op, :count, :avg_age, :min_age, :max_age
|
21
|
+
end
|
22
|
+
|
23
|
+
def peek(_options)
|
24
|
+
require "table_print"
|
25
|
+
tp Postqueue.default_queue.upcoming(subselect: false).limit(100).all
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/postqueue/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "ostruct"
|
2
2
|
|
3
3
|
require_relative "cli/options_parser"
|
4
|
+
require_relative "cli/stats"
|
4
5
|
|
5
6
|
module Postqueue
|
6
7
|
module CLI
|
@@ -12,14 +13,12 @@ module Postqueue
|
|
12
13
|
@options = OptionsParser.parse_args(argv)
|
13
14
|
|
14
15
|
case options.sub_command
|
15
|
-
when "stats"
|
16
|
+
when "stats", "peek"
|
16
17
|
connect_to_database!
|
17
|
-
|
18
|
-
tp Postqueue.item_class.find_by_sql(sql)
|
18
|
+
Stats.send options.sub_command, options
|
19
19
|
when "enqueue"
|
20
20
|
connect_to_database!
|
21
21
|
count = Postqueue.enqueue op: options.op, entity_id: options.entity_ids
|
22
|
-
puts "returned #{count.inspect}"
|
23
22
|
Postqueue.logger.info "Enqueued #{count} queue items"
|
24
23
|
when "process"
|
25
24
|
connect_to_instance!
|
@@ -7,18 +7,19 @@ module Postqueue
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def run!
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
set_default_runner unless @run
|
11
|
+
@run.call(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_default_runner
|
15
|
+
run do |queue|
|
16
|
+
loop do
|
17
|
+
queue.logger.debug "#{queue}: Processing until empty"
|
18
|
+
queue.process_until_empty
|
19
|
+
queue.logger.debug "#{queue}: sleeping"
|
20
|
+
sleep 1
|
18
21
|
end
|
19
22
|
end
|
20
|
-
|
21
|
-
run.call(self)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -1,14 +1,19 @@
|
|
1
1
|
module Postqueue
|
2
2
|
class Queue
|
3
|
+
def upcoming(relation = nil, subselect: true) #:nodoc:
|
4
|
+
relation = item_class.all if relation.nil?
|
5
|
+
relation = relation.select(:id, :entity_id, :op) if subselect
|
6
|
+
|
7
|
+
# Ordering by next_run_at and id should not strictly be necessary, but helps
|
8
|
+
# processing entries in the passed in order when enqueued at the same time.
|
9
|
+
relation.where("failed_attempts < ? AND next_run_at < ?", max_attemps, Time.now)
|
10
|
+
.order(:next_run_at, :id)
|
11
|
+
end
|
12
|
+
|
3
13
|
# Select and lock up to \a limit unlocked items in the queue. Used by
|
4
14
|
# select_and_lock_batch.
|
5
15
|
def select_and_lock(relation, limit:)
|
6
|
-
|
7
|
-
# processing entries in the passed in order when enqueued at the same time.
|
8
|
-
relation = relation
|
9
|
-
.select(:id, :entity_id, :op)
|
10
|
-
.where("failed_attempts < ? AND next_run_at < ?", max_attemps, Time.now)
|
11
|
-
.order(:next_run_at, :id)
|
16
|
+
relation = upcoming(relation)
|
12
17
|
|
13
18
|
# FOR UPDATE SKIP LOCKED selects and locks entries, but skips those that
|
14
19
|
# are already locked - preventing this transaction from being locked.
|
data/lib/postqueue/queue.rb
CHANGED
data/lib/postqueue/version.rb
CHANGED
@@ -21,7 +21,8 @@ describe "concurrency tests" do
|
|
21
21
|
log = File.open(LOG_FILE, "a")
|
22
22
|
queue = Postqueue.new
|
23
23
|
queue.on "*" do |_op, entity_ids|
|
24
|
-
sleep(0.0001)
|
24
|
+
sleep(0.0001)
|
25
|
+
log.write "#{entity_ids.first}\n"
|
25
26
|
end
|
26
27
|
queue.process_until_empty
|
27
28
|
log.close
|
@@ -33,9 +34,7 @@ describe "concurrency tests" do
|
|
33
34
|
def run_scenario(cnt, n_threads)
|
34
35
|
FileUtils.rm_rf LOG_FILE
|
35
36
|
|
36
|
-
queue = Postqueue.new
|
37
|
-
# queue.default_batch_size = 10
|
38
|
-
end
|
37
|
+
queue = Postqueue.new
|
39
38
|
|
40
39
|
benchmark "enqueuing #{cnt} ops" do
|
41
40
|
queue.enqueue op: "myop", entity_id: (1..cnt)
|
@@ -67,9 +66,7 @@ describe "concurrency tests" do
|
|
67
66
|
it "enqueues many entries" do
|
68
67
|
cnt = 1000
|
69
68
|
|
70
|
-
queue = Postqueue.new
|
71
|
-
# queue.default_batch_size = 10
|
72
|
-
end
|
69
|
+
queue = Postqueue.new
|
73
70
|
benchmark "enqueuing #{cnt} ops" do
|
74
71
|
queue.enqueue op: "myop", entity_id: (1..cnt)
|
75
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postqueue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/postqueue.rb
|
164
164
|
- lib/postqueue/cli.rb
|
165
165
|
- lib/postqueue/cli/options_parser.rb
|
166
|
+
- lib/postqueue/cli/stats.rb
|
166
167
|
- lib/postqueue/default_queue.rb
|
167
168
|
- lib/postqueue/item.rb
|
168
169
|
- lib/postqueue/item/enqueue.rb
|