activejob-retry 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -0
  3. data/.travis.yml +20 -5
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +9 -6
  6. data/Gemfile.lock +63 -51
  7. data/LICENSE +1 -1
  8. data/README.md +57 -25
  9. data/Rakefile +14 -13
  10. data/activejob-retry.gemspec +9 -12
  11. data/lib/active_job/retry.rb +69 -90
  12. data/lib/active_job/retry/constant_backoff_strategy.rb +50 -0
  13. data/lib/active_job/retry/constant_options_validator.rb +76 -0
  14. data/lib/active_job/retry/deserialize_monkey_patch.rb +17 -12
  15. data/lib/active_job/retry/errors.rb +6 -0
  16. data/lib/active_job/retry/variable_backoff_strategy.rb +34 -0
  17. data/lib/active_job/retry/variable_options_validator.rb +56 -0
  18. data/lib/active_job/retry/version.rb +1 -1
  19. data/spec/retry/constant_backoff_strategy_spec.rb +115 -0
  20. data/spec/retry/constant_options_validator_spec.rb +81 -0
  21. data/spec/retry/variable_backoff_strategy_spec.rb +121 -0
  22. data/spec/retry/variable_options_validator_spec.rb +83 -0
  23. data/spec/retry_spec.rb +114 -170
  24. data/spec/spec_helper.rb +3 -2
  25. data/test/adapters/backburner.rb +3 -0
  26. data/test/adapters/delayed_job.rb +7 -0
  27. data/test/adapters/inline.rb +1 -0
  28. data/test/adapters/qu.rb +3 -0
  29. data/test/adapters/que.rb +4 -0
  30. data/test/adapters/queue_classic.rb +2 -0
  31. data/test/adapters/resque.rb +2 -0
  32. data/test/adapters/sidekiq.rb +2 -0
  33. data/test/adapters/sneakers.rb +2 -0
  34. data/test/adapters/sucker_punch.rb +2 -0
  35. data/test/cases/adapter_test.rb +8 -0
  36. data/test/cases/argument_serialization_test.rb +84 -0
  37. data/test/cases/callbacks_test.rb +23 -0
  38. data/test/cases/job_serialization_test.rb +15 -0
  39. data/test/cases/logging_test.rb +114 -0
  40. data/test/cases/queue_naming_test.rb +102 -0
  41. data/test/cases/queuing_test.rb +44 -0
  42. data/test/cases/rescue_test.rb +35 -0
  43. data/test/cases/test_case_test.rb +14 -0
  44. data/test/cases/test_helper_test.rb +226 -0
  45. data/test/helper.rb +21 -0
  46. data/test/integration/queuing_test.rb +46 -0
  47. data/test/jobs/callback_job.rb +31 -0
  48. data/test/jobs/gid_job.rb +10 -0
  49. data/test/jobs/hello_job.rb +9 -0
  50. data/test/jobs/logging_job.rb +12 -0
  51. data/test/jobs/nested_job.rb +12 -0
  52. data/test/jobs/rescue_job.rb +31 -0
  53. data/test/models/person.rb +20 -0
  54. data/test/support/backburner/inline.rb +8 -0
  55. data/test/support/delayed_job/delayed/backend/test.rb +111 -0
  56. data/test/support/delayed_job/delayed/serialization/test.rb +0 -0
  57. data/test/support/integration/adapters/backburner.rb +38 -0
  58. data/test/support/integration/adapters/delayed_job.rb +20 -0
  59. data/test/support/integration/adapters/que.rb +37 -0
  60. data/test/support/integration/adapters/resque.rb +49 -0
  61. data/test/support/integration/adapters/sidekiq.rb +58 -0
  62. data/test/support/integration/dummy_app_template.rb +28 -0
  63. data/test/support/integration/helper.rb +30 -0
  64. data/test/support/integration/jobs_manager.rb +27 -0
  65. data/test/support/integration/test_case_helpers.rb +48 -0
  66. data/test/support/job_buffer.rb +19 -0
  67. data/test/support/que/inline.rb +9 -0
  68. metadata +60 -12
  69. data/lib/active_job-retry.rb +0 -14
  70. data/lib/active_job/retry/exponential_backoff.rb +0 -92
  71. data/lib/active_job/retry/exponential_options_validator.rb +0 -57
  72. data/lib/active_job/retry/invalid_configuration_error.rb +0 -6
  73. data/lib/active_job/retry/options_validator.rb +0 -84
@@ -1,57 +0,0 @@
1
- module ActiveJob
2
- module Retry
3
- class ExponentialOptionsValidator
4
- DELAY_MULTIPLIER_KEYS = %i(min_delay_multiplier max_delay_multiplier).freeze
5
-
6
- def initialize(options)
7
- @options = options
8
- @retry_limit = options[:limit] || options.fetch(:strategy, []).length
9
- end
10
-
11
- def validate!
12
- validate_strategy!
13
- validate_delay_multipliers!
14
- end
15
-
16
- private
17
-
18
- attr_reader :options, :retry_limit
19
-
20
- def validate_strategy!
21
- unless options[:strategy]
22
- raise InvalidConfigurationError, "You must define a backoff strategy"
23
- end
24
-
25
- return unless retry_limit
26
-
27
- unless retry_limit > 0
28
- raise InvalidConfigurationError,
29
- "Exponential backoff cannot be used with infinite or no retries"
30
- end
31
-
32
- return if options[:strategy].length == retry_limit
33
-
34
- raise InvalidConfigurationError, "Strategy must have a delay for each retry"
35
- end
36
-
37
- def validate_delay_multipliers!
38
- unless both_or_neither_multiplier_supplied?
39
- raise InvalidConfigurationError,
40
- "If one of min/max_delay_multiplier is supplied, both are required"
41
- end
42
-
43
- return unless options[:min_delay_multiplier] && options[:max_delay_multiplier]
44
-
45
- return if options[:min_delay_multiplier] <= options[:max_delay_multiplier]
46
-
47
- raise InvalidConfigurationError,
48
- "min_delay_multiplier must be less than or equal to max_delay_multiplier"
49
- end
50
-
51
- def both_or_neither_multiplier_supplied?
52
- supplied = DELAY_MULTIPLIER_KEYS.map { |key| options.key?(key) }
53
- supplied.none? || supplied.all?
54
- end
55
- end
56
- end
57
- end
@@ -1,6 +0,0 @@
1
- module ActiveJob
2
- module Retry
3
- class InvalidConfigurationError < StandardError
4
- end
5
- end
6
- end
@@ -1,84 +0,0 @@
1
- module ActiveJob
2
- module Retry
3
- class OptionsValidator
4
- def initialize(options)
5
- @options = options
6
- end
7
-
8
- def validate!
9
- validate_limit!
10
- validate_delay!
11
- validate_fatal_exceptions!
12
- validate_retry_exceptions!
13
- end
14
-
15
- private
16
-
17
- attr_reader :options
18
-
19
- # Limit must be an integer >= -1
20
- # If it is -1 you *must* set `infinite_job: true` and understand that you're
21
- # entering a world of pain and your ops team might hurt you.
22
- def validate_limit!
23
- return unless options[:limit]
24
-
25
- unless options[:limit].is_a?(Fixnum)
26
- raise InvalidConfigurationError, "Limit must be an integer"
27
- end
28
-
29
- raise InvalidConfigurationError, "Limit must be >= -1" if options[:limit] < -1
30
-
31
- if options[:limit] == -1 && !options[:infinite_job]
32
- raise InvalidConfigurationError,
33
- "You must set `infinite_job: true` to use an infinite job"
34
- end
35
- end
36
-
37
- # Delay must be non-negative
38
- def validate_delay!
39
- return unless options[:delay]
40
-
41
- unless options[:delay] >= 0
42
- raise InvalidConfigurationError, "Delay must be non-negative"
43
- end
44
- end
45
-
46
- # Fatal exceptions must be an array (cannot be nil, since then all exceptions would
47
- # be fatal - for that just set `limit: 0`)
48
- def validate_fatal_exceptions!
49
- return unless options[:fatal_exceptions]
50
-
51
- unless options[:retry_exceptions].nil?
52
- raise InvalidConfigurationError,
53
- "fatal_exceptions and retry_exceptions cannot be used together"
54
- end
55
-
56
- unless options[:fatal_exceptions].is_a?(Array)
57
- raise InvalidConfigurationError, "fatal_exceptions must be an array"
58
- end
59
-
60
- unless options[:fatal_exceptions].all? { |ex| ex.is_a?(Class) && ex <= Exception }
61
- raise InvalidConfigurationError, "fatal_exceptions must be exceptions!"
62
- end
63
- end
64
-
65
- # Retry exceptions must be an array of exceptions or `nil` to retry any exception
66
- def validate_retry_exceptions!
67
- return unless options[:retry_exceptions]
68
-
69
- unless options[:fatal_exceptions].nil?
70
- raise InvalidConfigurationError,
71
- "retry_exceptions and fatal_exceptions cannot be used together"
72
- end
73
-
74
- unless options[:retry_exceptions].is_a?(Array)
75
- raise InvalidConfigurationError, "retry_exceptions must be an array or nil"
76
- end
77
-
78
- unless options[:retry_exceptions].all? { |ex| ex.is_a?(Class) && ex <= Exception }
79
- raise InvalidConfigurationError, "retry_exceptions must be exceptions!"
80
- end
81
- end
82
- end
83
- end
84
- end