services 0.2.12 → 0.2.13

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: fa15ea76009e9ba974b7e3faf90a467368917660
4
- data.tar.gz: 5c0dcc6db009e65fb210e9883feb604329d1bf5b
3
+ metadata.gz: 633721b985b22ab22c0f05134d9d596cb1c3e8e7
4
+ data.tar.gz: 296c454079604408722442164aec3999a842ca54
5
5
  SHA512:
6
- metadata.gz: d3684cdccaf566dae3c4f018127efe9d947692488ec30bb714c8ebaca9d134dd876750483b6794b4bc9b26a589966e0e533a455b98e4ac1bdcbb85fcb810c682
7
- data.tar.gz: 5c98b4049291181ccd59abf71c6ade54a8aac194521ed5c2ad2c9e70380ee88930ebb94734138fea1496229491ee88d231c21401ecd46c4e0719f50f7f6356f5
6
+ metadata.gz: fd8b3a5e499a3c6ba052d6a6dd6fb84dc25be6677571aca9d8aeb6192ebb54334f3d4604cf51da3181a60c93d0b70550b5ef396dbfe9b76ac66ffdfbbf9499ee
7
+ data.tar.gz: 1766463f9ab6d43dcc242dccaa2c0e6d585945f6613e59b17627bfceb99868c112ce2594d83435aff94982e9faa6059e5e07f1efa69b02bb9387c56fb1bf7baf
@@ -30,13 +30,11 @@ module Services
30
30
  when :fail
31
31
  raise_non_unique_error
32
32
  when :reschedule
33
- @error_count = (Services.configuration.redis.get(error_count_key) || 0).to_i
34
- if @error_count >= MAX_RETRIES
33
+ if error_count >= MAX_RETRIES
35
34
  raise_non_unique_error
36
35
  else
37
- @error_count += 1
36
+ increase_error_count
38
37
  reschedule
39
- Services.configuration.redis.setex error_count_key, retry_delay + ONE_HOUR, @error_count
40
38
  end
41
39
  end
42
40
  false
@@ -64,21 +62,38 @@ module Services
64
62
  raise self.class::NotUniqueError, message
65
63
  end
66
64
 
65
+ def convert_for_rescheduling(arg)
66
+ case arg
67
+ when Array
68
+ arg.map do |array_arg|
69
+ convert_for_rescheduling array_arg
70
+ end
71
+ when Fixnum, String, TrueClass, FalseClass, NilClass
72
+ arg
73
+ when service_class
74
+ arg.id
75
+ else
76
+ raise "Don't know how to convert arg #{arg.inspect} for rescheduling."
77
+ end
78
+ end
79
+
67
80
  def reschedule
68
81
  # Convert service args to fixnums first
69
82
  reschedule_args = @service_args.map do |arg|
70
- case arg
71
- when Fixnum, String, TrueClass, FalseClass, NilClass
72
- arg
73
- when service_class && arg.respond_to?(:id)
74
- arg.id
75
- else
76
- raise "Don't know how to convert arg #{arg.inspect} for rescheduling."
77
- end
83
+ convert_for_rescheduling arg
78
84
  end
79
85
  self.class.perform_in retry_delay, *reschedule_args
80
86
  end
81
87
 
88
+ def error_count
89
+ (Services.configuration.redis.get(error_count_key) || 0).to_i
90
+ end
91
+
92
+ def increase_error_count
93
+ Services.configuration.redis.incr error_count_key
94
+ Services.configuration.redis.setex error_count_key, retry_delay + ONE_HOUR, error_count
95
+ end
96
+
82
97
  def uniqueness_key(args)
83
98
  [
84
99
  KEY_PREFIX,
@@ -99,7 +114,7 @@ module Services
99
114
  end
100
115
 
101
116
  def retry_delay
102
- (@error_count ** 3) + 5
117
+ (error_count ** 3) + 5
103
118
  end
104
119
  end
105
120
  end
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '0.2.12'
2
+ VERSION = '0.2.13'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer