sidekiq-postpone 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 84a89193bb8e0ab78b7b5150307f5e59a130d8f7cd9042621c35bac7a1648ab4
4
- data.tar.gz: 2cfae440c4f663e51bbf7866defac44525a0a2b77bbf4baf7e1b39278b535609
3
+ metadata.gz: 634e909de058d8e5c067a0007f7e83c20e764552677104e53fa80add81e9ad54
4
+ data.tar.gz: 8b906c5ce4efc944e6e388736310fb6c71ff304f72a19ac388367c43cb67b9fc
5
5
  SHA512:
6
- metadata.gz: ee5312224a86a288ad8a0615ddb5dea981606fcaa602fa65fa840c8143fb836e42e0d9d5ea6667060a63df8edd9937db32b2606e0b10887d057336dff26f4a01
7
- data.tar.gz: 1e39d84d4da4d3fc0d2b637367a9e7752b990dec5014e555764cbc480c5b13a616e7992d97bc309ef3a469c414f9290444acb548ad4b2dc49c51e88d8ee1601f
6
+ metadata.gz: bff94b3c27b98308a5bbe2d8771d626583ddb66f10a8df9524262931c3993a278d264539032a969b15f58b1c7314a9cf1e5d554a517e4cef8944a397e0b8ef82
7
+ data.tar.gz: 8e05448529a78055810c04d5d2bc750138114a0081a3634d46d255ad89b24abba56dc763c7ef583393d788e3701532d8045114a533b09b632b88f84efc16d307
data/.travis.yml CHANGED
@@ -4,9 +4,10 @@ services:
4
4
  - redis-server
5
5
  rvm:
6
6
  - 2.1
7
- - 2.2.2
8
- - 2.3.0
7
+ - 2.2
8
+ - 2.3
9
9
  - 2.4
10
+ - 2.5
10
11
  gemfile:
11
12
  - gemfiles/sidekiq_3.0.gemfile
12
13
  - gemfiles/sidekiq_3.1.gemfile
@@ -18,14 +19,16 @@ gemfile:
18
19
  - gemfiles/sidekiq_4.1.gemfile
19
20
  - gemfiles/sidekiq_4.2.gemfile
20
21
  - gemfiles/sidekiq_5.0.gemfile
22
+ - gemfiles/sidekiq_5.1.gemfile
21
23
  - gemfiles/sidekiq_master.gemfile
22
24
  matrix:
23
25
  fast_finish: true
24
26
  exclude:
27
+ - gemfile: gemfiles/sidekiq_5.1.gemfile
28
+ rvm: 2.1
25
29
  - gemfile: gemfiles/sidekiq_5.0.gemfile
26
30
  rvm: 2.1
27
31
  - gemfile: gemfiles/sidekiq_master.gemfile
28
- rvm: 2.1
29
32
 
30
33
  before_install: gem install bundler -v 1.15
31
34
  script:
data/Appraisals CHANGED
@@ -38,6 +38,10 @@ appraise 'sidekiq-5.0' do
38
38
  gem 'sidekiq', '~> 5.0.0'
39
39
  end
40
40
 
41
+ appraise 'sidekiq-5.1' do
42
+ gem 'sidekiq', '~> 5.1.0'
43
+ end
44
+
41
45
  appraise 'sidekiq-master' do
42
46
  gem 'sidekiq', github: 'mperham/sidekiq'
43
47
  end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sidekiq", "~> 5.1.0"
6
+
7
+ gemspec :path => "../"
@@ -11,8 +11,8 @@ class Sidekiq::Postpone
11
11
  setup_schedule
12
12
  end
13
13
 
14
- def wrap(join_parent: true, flush: true)
15
- enter!
14
+ def wrap(join_parent: true, flush: true, **options)
15
+ enter!(**options)
16
16
  begin
17
17
  yield self
18
18
  rescue
@@ -22,7 +22,7 @@ class Sidekiq::Postpone
22
22
  if join_parent && (parent = Thread.current[:sidekiq_postpone_stack][-2])
23
23
  join!(parent)
24
24
  elsif flush
25
- flush!
25
+ @flush_on_leave = true
26
26
  end
27
27
  end
28
28
  ensure
@@ -34,12 +34,18 @@ class Sidekiq::Postpone
34
34
  end
35
35
 
36
36
  def push(payloads)
37
+ if @ignore
38
+ payloads, ignored = payloads.partition(&@ignore)
39
+ ignored = nil if ignored.empty?
40
+ return ignored if payloads.empty?
41
+ end
37
42
  if payloads.first['at']
38
43
  @schedule.concat(payloads)
39
44
  else
40
45
  q = payloads.first['queue']
41
46
  @queues[q].concat(payloads)
42
47
  end
48
+ ignored
43
49
  end
44
50
 
45
51
  def clear!
@@ -48,15 +54,17 @@ class Sidekiq::Postpone
48
54
  end
49
55
 
50
56
  def flush!
57
+ current_postpone = Thread.current[:sidekiq_postpone]
51
58
  return if empty?
52
59
 
53
- current_postpone = Thread.current[:sidekiq_postpone]
54
60
  Thread.current[:sidekiq_postpone] = nil # activate real raw_push
55
61
 
56
62
  client = Sidekiq::Client.new(*@client_args)
57
- raw_push = client.method(:raw_push)
58
- @queues.each_value(&raw_push)
59
- raw_push.(@schedule) unless @schedule.empty?
63
+
64
+ @queues.each_value { |item| client.raw_push(item) }
65
+ client.raw_push(@schedule) unless @schedule.empty?
66
+
67
+ clear!
60
68
  ensure
61
69
  Thread.current[:sidekiq_postpone] = current_postpone
62
70
  end
@@ -76,18 +84,23 @@ class Sidekiq::Postpone
76
84
  @queues.empty? && @schedule.empty?
77
85
  end
78
86
 
87
+ def jids
88
+ [*@queues.values.flatten(1), *@schedule].map! { |j| j['jid'] }
89
+ end
90
+
79
91
  protected
80
92
 
81
93
  attr_reader :queues, :schedule
82
94
 
83
95
  private
84
96
 
85
- def enter!
97
+ def enter!(ignore: nil)
86
98
  if @entered
87
99
  raise 'Sidekiq::Postpone#wrap is not re-enterable on the same instance'
88
100
  else
89
101
  @entered = true
90
102
  end
103
+ @ignore = ignore
91
104
  Thread.current[:sidekiq_postpone_stack] ||= []
92
105
  Thread.current[:sidekiq_postpone_stack].push(self)
93
106
  Thread.current[:sidekiq_postpone] = self
@@ -98,6 +111,11 @@ class Sidekiq::Postpone
98
111
  head = Thread.current[:sidekiq_postpone_stack].last
99
112
  Thread.current[:sidekiq_postpone] = head
100
113
  @entered = false
114
+ @ignore = nil
115
+ if @flush_on_leave
116
+ @flush_on_leave = false
117
+ flush!
118
+ end
101
119
  end
102
120
 
103
121
  def setup_queues
@@ -3,7 +3,9 @@ class Sidekiq::Postpone
3
3
  def raw_push(payloads)
4
4
  postpone = Thread.current[:sidekiq_postpone]
5
5
  if postpone
6
- postpone.push(payloads)
6
+ ignored = postpone.push(payloads)
7
+ super(ignored) if ignored
8
+ true
7
9
  else
8
10
  super
9
11
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  class Postpone
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-postpone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kochnev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-28 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -125,6 +125,7 @@ files:
125
125
  - gemfiles/sidekiq_4.1.gemfile
126
126
  - gemfiles/sidekiq_4.2.gemfile
127
127
  - gemfiles/sidekiq_5.0.gemfile
128
+ - gemfiles/sidekiq_5.1.gemfile
128
129
  - gemfiles/sidekiq_master.gemfile
129
130
  - lib/sidekiq/postpone.rb
130
131
  - lib/sidekiq/postpone/core_ext.rb