postqueue 0.5.2 → 0.5.3

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: a52b3b91a65a4f5f48a6d12395c0dba897190aef
4
- data.tar.gz: 0d8cecbc763a5a1797d309116f1ccc6ae82877ba
3
+ metadata.gz: ad176bce5f7bba7fda654b053e5fa32acd41abdd
4
+ data.tar.gz: 646743647918dbc637ea6e740f4015b3ef942f82
5
5
  SHA512:
6
- metadata.gz: 53c4d7dcd874b253451268ebb34cccec7a7545b92c259cfde136890080eb39b608fe48c44b7ad5fecaef542f2dbf2cd81535abcdcd07a2e706afeb36e5765452
7
- data.tar.gz: 81a9ff3a9f19a2bffbca50aabf44b9ee2129279842a252f10f4eed786c9f83dbebce0606378edf78bb946848e0683b3d78804239d1606787227458691572c31f
6
+ metadata.gz: ffd319be64f642202f294c85b7c2d89d310b4d42dc4654cbb6d3d4d2bf65ffcd57ab80a6aa9aa328062a7243ca5d2696d03e120993b46db1f49a578c65a124e2
7
+ data.tar.gz: 587ab795e8b9e239f8e126d6325418dca8d9014999c1da4d696ddbc19115074497be3d5ee00fd457ca2dac234f7a2ff21801be154457c5b03f34428c14466ce1
@@ -16,7 +16,11 @@ module Postqueue
16
16
  def parse_args
17
17
  require "optparse"
18
18
  options = OpenStruct.new
19
- options.sub_command = argv.shift || usage!
19
+ options.sub_command = argv.shift || "stats"
20
+
21
+ unless %w(stats peek enqueue run process).include?(options.sub_command)
22
+ usage!
23
+ end
20
24
 
21
25
  case options.sub_command
22
26
  when "enqueue"
@@ -32,13 +36,22 @@ module Postqueue
32
36
  argv.shift || usage!
33
37
  end
34
38
 
35
- def usage!
39
+ def usage
36
40
  STDERR.puts <<-USAGE
37
- postqueue stats
41
+ This is postqueue #{Postqueue::VERSION}. Usage examples:
42
+
43
+ postqueue [ stats ]
44
+ postqueue peek
38
45
  postqueue enqueue op entity_id,entity_id,entity_id
39
46
  postqueue run
47
+ postqueue help
40
48
  postqueue process
41
- USAGE
49
+
50
+ USAGE
51
+ end
52
+
53
+ def usage!
54
+ usage
42
55
  exit 1
43
56
  end
44
57
  end
@@ -10,14 +10,22 @@ module Postqueue
10
10
  sql = <<-SQL
11
11
  SELECT op,
12
12
  COUNT(*) AS count,
13
+ failed_attempts,
14
+ CASE
15
+ WHEN failed_attempts >= 5 THEN 'FAILED'
16
+ WHEN failed_attempts > 0 THEN 'RETRY'
17
+ WHEN next_run_at < now() THEN 'READY'
18
+ ELSE 'WAIT'
19
+ END AS status,
13
20
  MIN(now() - created_at) AS min_age,
14
21
  MAX(now() - created_at) AS max_age,
15
22
  AVG(now() - created_at) AS avg_age
16
- FROM #{Postqueue.item_class.table_name} GROUP BY op
23
+ FROM #{Postqueue.item_class.table_name}
24
+ GROUP BY op, failed_attempts, status
17
25
  SQL
18
26
 
19
27
  recs = Postqueue.item_class.find_by_sql(sql)
20
- tp recs, :op, :count, :avg_age, :min_age, :max_age
28
+ tp recs, :status, :op, :failed_attempts, :count, :avg_age, :min_age, :max_age
21
29
  end
22
30
 
23
31
  def peek(_options)
data/lib/postqueue/cli.rb CHANGED
@@ -30,7 +30,7 @@ module Postqueue
30
30
  end
31
31
 
32
32
  def connect_to_rails!
33
- if File.exists?("config/environment.rb")
33
+ if File.exist?("config/environment.rb")
34
34
  load "config/environment.rb"
35
35
  else
36
36
  logger.warn "Trying to load postqueue configuration from config/postqueue.rb"
@@ -12,7 +12,7 @@ module Postqueue
12
12
  extend SingleForwardable
13
13
 
14
14
  def_delegators :default_queue, :enqueue
15
- def_delegators :default_queue, :item_class, :batch_sizes, :on
15
+ def_delegators :default_queue, :item_class, :batch_sizes, :on, :on_exception
16
16
  def_delegators :default_queue, :process, :process_one
17
17
  def_delegators :default_queue, :processing
18
18
  def_delegators :default_queue, :run, :run!
@@ -52,6 +52,7 @@ module Postqueue
52
52
  item_class.postpone items.map(&:id)
53
53
  log_exception(e, match.op, entity_ids)
54
54
  on_exception.call(e, match.op, entity_ids)
55
+ 0
55
56
  end
56
57
  end
57
58
  end
@@ -38,7 +38,7 @@ module Postqueue
38
38
  end
39
39
 
40
40
  on "fail" do |_op, entity_ids|
41
- raise RuntimeError, "Postqueue test failure, w/entity_ids: #{entity_ids.inspect}"
41
+ raise "Postqueue test failure, w/entity_ids: #{entity_ids.inspect}"
42
42
  end
43
43
 
44
44
  on :missing_handler do |op, entity_ids|
@@ -1,3 +1,3 @@
1
1
  module Postqueue
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -16,13 +16,13 @@ describe "enqueuing" do
16
16
  end
17
17
 
18
18
  it "enqueues arrays" do
19
- queue.enqueue op: "myop", entity_id: [13,14,15]
20
- expect(items.pluck(:entity_id)).to eq([12,13,14,15])
19
+ queue.enqueue op: "myop", entity_id: [13, 14, 15]
20
+ expect(items.pluck(:entity_id)).to eq([12, 13, 14, 15])
21
21
  end
22
22
 
23
23
  it "enqueues sets" do
24
- queue.enqueue op: "myop", entity_id: Set.new([13,14,15])
25
- expect(items.pluck(:entity_id)).to eq([12,13,14,15])
24
+ queue.enqueue op: "myop", entity_id: Set.new([13, 14, 15])
25
+ expect(items.pluck(:entity_id)).to eq([12, 13, 14, 15])
26
26
  end
27
27
 
28
28
  it "sets defaults" do
@@ -44,9 +44,9 @@ describe "process mode" do
44
44
  end
45
45
 
46
46
  it "raises an error for invalid ops" do
47
- expect {
47
+ expect do
48
48
  queue.enqueue op: "invalid", entity_id: 12
49
- }.to raise_error(Postqueue::MissingHandler)
49
+ end.to raise_error(Postqueue::MissingHandler)
50
50
  end
51
51
  end
52
52
  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.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel