sidekiq_portal 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e413dfa69dae938ee861290b621eb99252cbcba42c09d1eaa541d1fb49e1675
4
- data.tar.gz: 01d1b01fc9c84920425212d964763372c0f2c4129eb179129bd60932fde2b374
3
+ metadata.gz: 23dc75354e3f173ffc8fdaa30634f08509374eaecb190226344073c5e1ba0bbe
4
+ data.tar.gz: c457e2865d1fac05fc1822f4ba4fea2121b29c7649ffabcff91039cb50abde02
5
5
  SHA512:
6
- metadata.gz: afcb5900eab9338ab000fd3f540f827ecc6e0c5b9907789e30f8b9c729bf970b771dfca679853b5484174c90361a48381298869b4447105a0a2c28670065578e
7
- data.tar.gz: 7cac31cd6ad9a3da4a253afe6fbb47cd4344fbea1d73ca685b39c224d3d05cc53dd8c8320d77920a303224ce5548ce30c96f2c84d5720508c3990e2d5af61d92
6
+ metadata.gz: a156ef577a6b09f906819c16b31234ee6e053f2d4a179acdaf84089433b99669ea14101ded51cd211c45d01367acdd81d4eb5c2a389f6bdddb96c78db48f6dd9
7
+ data.tar.gz: 92e396e45095fe17dd02f2ad2c1b58fc3f5e342ec45771b78d8a89cba6491d54b22037fd697378234ce202e5fadeea505a42acadb8b3ca620c2b0bd8e2450148
data/.gitignore CHANGED
@@ -7,10 +7,10 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  .rspec_status
10
- Gemfile.lock
11
10
  /.idea
12
11
  .ruby-version
13
12
  /.vscode/
14
13
  /spec/artifacts/
15
14
  /gemfiles/*.gemfile.lock
16
15
  *.gem
16
+ Gemfile.lock
@@ -5,7 +5,7 @@ inherit_gem:
5
5
  - lib/rubocop.rspec.yml
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.6.5
8
+ TargetRubyVersion: 2.4.9
9
9
  Include:
10
10
  - lib/**/*.rb
11
11
  - spec/**/*.rb
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.2.0] - 2020-01-04
5
+ ### Added
6
+ - Sidekiq's job retry mechanism emulation;
7
+
4
8
  ## [0.1.1] - 2019-12-24
5
9
 
6
10
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Rustam Ibragimov
3
+ Copyright (c) 2019-2020 Rustam Ibragimov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -54,9 +54,10 @@ require 'sidekiq_portal'
54
54
 
55
55
  ## Configuration
56
56
 
57
- - `default_timezone` (`UTC` by default) - global time zone for your jobs;
58
- - `retries_count` - Sidekiq's built-in retry mechanism simulation;
59
- - `scheduler_config` - `sidekiq-scheduler`-based scheduler configuration;;
57
+ - `default_timezone` - global time zone for your jobs (`UTC` by default);
58
+ - `retry_count` - Sidekiq's built-in retry mechanism simulation (`0` by default);
59
+ - `retry_on` - retry only on a set of exceptions (`[StandardError]` by default);
60
+ - `scheduler_config` - `sidekiq-scheduler`-based scheduler configuration (`{}` by default (non-configured));
60
61
  - `Sidekiq::Portal.reload!(&configuration)` - reload portal configurations;
61
62
 
62
63
  In your `spec_helper.rb`:
@@ -64,8 +65,9 @@ In your `spec_helper.rb`:
64
65
  ```ruby
65
66
  # portal configuration
66
67
  Sidekiq::Portal.setup! do |config|
67
- config.default_timezone = 'UTC'
68
- config.retries_count = 1
68
+ config.default_timezone = 'UTC' # 'UTC' by default
69
+ config.retry_count = 3 # 0 by default
70
+ config.retry_on = [StandardError] # [StandardError] by default
69
71
 
70
72
  # pre-defined sidekiq-scheduler configs (Rails example)
71
73
  config.scheduler_cofnig = Rails.application.config_for(:sidekiq)[:schedule]
@@ -146,8 +148,7 @@ end
146
148
 
147
149
  - `Sidekiq::Testing.portal!` test mode with support for `:inline` and `:fake`;
148
150
  (`Sidekiq::Testing.inline!` and `Sidekiq::Testing.fake` respectively);
149
- - support for `ActiveSupport::Timezone` instances in `default_timezone` config;
150
- - support for retries;
151
+ - support for `ActiveSupport::TimeZone` instances in `default_timezone` config;
151
152
  - rspec matchers;
152
153
  - `#reload!` should use previosly defined settings?;
153
154
  - support for `Sidekiq::Worker` job backend;
@@ -155,6 +156,9 @@ end
155
156
  - more specs;
156
157
  - documentation and examples for instance-based portals (`Sidekiq::Portal.new(&configuration)`);
157
158
  - job execution randomization (for jobs which should be invoked at the same time);
159
+ - configurable in-line invokations (with job list config);
160
+ - configurable and conditional portal invokation (run over all specs or only over the one or etc)
161
+ (suitable for unit tests);
158
162
 
159
163
  ## License
160
164
 
@@ -21,14 +21,35 @@ class Sidekiq::Portal::Config < Qonfig::DataSet
21
21
  # @since 0.1.0
22
22
  DEFAUL_RETRIES_COUNT = 0
23
23
 
24
+ # @return [Array<Exception>]
25
+ #
26
+ # @api private
27
+ # @since 0.1.0
28
+ RETRY_ON_EXCEPTIONS = [StandardError].freeze
29
+
30
+ # @since 0.1.0
24
31
  setting :default_timezone, DEFAULT_TIMEZONE
25
- setting :retries_count, DEFAUL_RETRIES_COUNT
32
+ # @since 0.1.0
33
+ setting :retry_count, DEFAUL_RETRIES_COUNT
34
+ # @since 0.1.0
35
+ setting :retry_on, RETRY_ON_EXCEPTIONS
36
+ # @since 0.1.0
26
37
  setting :scheduler_config, EMPTY_SCHEDULER_CONFIG
27
38
 
39
+ # @since 0.1.0
28
40
  validate :default_timezone do |value|
29
41
  value.is_a?(String) && !ActiveSupport::TimeZone[value].nil?
30
42
  end
31
43
 
32
- validate :retries_count, :integer, strict: true
44
+ # @since 0.1.0
45
+ validate :retry_on do |value|
46
+ value.is_a?(Array) && (value.all? do |exception_klass|
47
+ exception_klass.is_a?(Class) && exception_klass <= ::Exception
48
+ end)
49
+ end
50
+
51
+ # @since 0.1.0
52
+ validate :retry_count, :integer, strict: true
53
+ # @since 0.1.0
33
54
  validate :scheduler_config, :hash, strict: true
34
55
  end
@@ -52,7 +52,7 @@ class Sidekiq::Portal::JobManager
52
52
  .map!(&:time_points)
53
53
  .tap(&:flatten!)
54
54
  .tap(&:sort!)
55
- .tap(&:uniq)
55
+ .tap(&:uniq!)
56
56
  .tap { |points| points.select! { |point| point <= Time.current } }
57
57
  end
58
58
 
@@ -10,19 +10,18 @@ class Sidekiq::Portal::JobManager::Builder
10
10
  # @api private
11
11
  # @since 0.1.0
12
12
  def build(config)
13
- new(config.settings.scheduler_config, config.settings.default_timezone).build
13
+ new(config).build
14
14
  end
15
15
  end
16
16
 
17
- # @param scheduled_jobs_config [Hash]
18
- # @param timezone [String]
17
+ # @param config [Sidekiq::Portal::Config]
19
18
  # @return [void]
20
19
  #
21
20
  # @api private
22
21
  # @since 0.1.0
23
- def initialize(scheduled_jobs_config, timezone)
24
- @scheduled_jobs_config = scheduled_jobs_config
25
- @timezone = timezone
22
+ def initialize(config)
23
+ @scheduled_jobs_config = config.settings.scheduler_config
24
+ @timezone = config.settings.default_timezone
26
25
  end
27
26
 
28
27
  # @return [Sidekiq::Portal::Manager]
@@ -5,14 +5,74 @@
5
5
  class Sidekiq::Portal::JobRunner
6
6
  require_relative 'job_runner/builder'
7
7
 
8
+ # @param retry_count [Integer]
9
+ # @parma retry_on_exceptions [Array<Class<Exception>>]
10
+ # @return [void]
11
+ #
12
+ # @api private
13
+ # @since 0.1.0
14
+ def initialize(retry_count, retry_on_exceptions)
15
+ @retry_count = retry_count
16
+ @retry_on_exceptions = retry_on_exceptions
17
+ end
18
+
8
19
  # @param job [Sidekiq::Portal::Job]
9
20
  #
10
21
  # @api private
11
22
  # @since 0.1.0
12
23
  def run(job)
13
- return unless job.timeline.time_has_come?
24
+ return unless time_has_come?(job)
25
+ actualize_internal_job_state(job)
26
+ perform(job)
27
+ end
28
+
29
+ private
30
+
31
+ # @return [Integer]
32
+ #
33
+ # @api private
34
+ # @since 0.1.0
35
+ attr_reader :retry_count
36
+
37
+ # @return [Arrray<Class<Exception>>]
38
+ #
39
+ # @api private
40
+ # @since 0.1.0
41
+ attr_reader :retry_on_exceptions
42
+
43
+ # @param job [Sidekiq::Portal::Job]
44
+ # @return [Boolean]
45
+ #
46
+ # @api private
47
+ # @since 0.1.0
48
+ def time_has_come?(job)
49
+ job.timeline.time_has_come?
50
+ end
14
51
 
52
+ # @param job [Sidekiq::Portal::Job]
53
+ # @return [void]
54
+ #
55
+ # @api private
56
+ # @since 0.1.0
57
+ def actualize_internal_job_state(job)
15
58
  job.timeline.actualize_time!
59
+ end
60
+
61
+ # @param job [Sidekiq::Portal::Job]
62
+ # @param perform_attempt [Integer]
63
+ # @return [void]
64
+ #
65
+ # @raise [Exception]
66
+ #
67
+ # @api private
68
+ # @since 0.1.0
69
+ def perform(job, perform_attempt = 1)
16
70
  job.klass.perform_later
71
+ rescue => error
72
+ if retry_on_exceptions.include?(error.class)
73
+ (perform_attempt == retry_count) ? raise(error) : perform(job, perform_attempt.next)
74
+ else
75
+ raise(error)
76
+ end
17
77
  end
18
78
  end
@@ -10,7 +10,10 @@ module Sidekiq::Portal::JobRunner::Builder
10
10
  # @api private
11
11
  # @since 0.1.0
12
12
  def build(config)
13
- Sidekiq::Portal::JobRunner.new
13
+ Sidekiq::Portal::JobRunner.new(
14
+ config.settings.retry_count,
15
+ config.settings.retry_on
16
+ )
14
17
  end
15
18
  end
16
19
  end
@@ -10,6 +10,6 @@ module Sidekiq
10
10
  #
11
11
  # @api public
12
12
  # @since 0.1.0
13
- VERSION = '0.1.1'
13
+ VERSION = '0.2.0'
14
14
  end
15
15
  end
@@ -13,9 +13,9 @@ Gem::Specification.new do |spec|
13
13
  spec.email = ['iamdaiver@icloud.com']
14
14
 
15
15
  spec.summary =
16
- 'Sidekiq::Portal - emulate job activity in tests when you work with time traveling.'
16
+ 'Sidekiq::Portal - scheduled jobs invocation emulation for test environments '
17
17
  spec.description =
18
- 'Sidekiq::Portal - emulate job activity in tests when you work with time traveling.'
18
+ 'Sidekiq::Portal - emulate scheduled job activity in tests when you work with time traveling.'
19
19
 
20
20
  spec.homepage = 'https://github.com/0exp/sidekiq_portal'
21
21
  spec.license = 'MIT'
@@ -30,16 +30,16 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_dependency 'qonfig', '~> 0.23'
32
32
  spec.add_dependency 'fugit', '~> 1.3'
33
- spec.add_dependency 'activesupport', '>= 4'
33
+ spec.add_dependency 'activesupport', '>= 4', '< 7'
34
34
 
35
- spec.add_development_dependency 'armitage-rubocop', '~> 0.77'
35
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.78'
36
36
  spec.add_development_dependency 'rspec', '~> 3.9.0'
37
37
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
38
38
 
39
- spec.add_development_dependency 'sidekiq', '>= 5'
39
+ spec.add_development_dependency 'sidekiq', '>= 5', '< 7'
40
40
  spec.add_development_dependency 'timecop', '~> 0.9'
41
41
 
42
- spec.add_development_dependency 'bundler'
43
- spec.add_development_dependency 'rake'
44
- spec.add_development_dependency 'pry'
42
+ spec.add_development_dependency 'bundler', '~> 2.1'
43
+ spec.add_development_dependency 'rake', '~> 13.0'
44
+ spec.add_development_dependency 'pry', '~> 0.12'
45
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_portal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-24 00:00:00.000000000 Z
11
+ date: 2020-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: qonfig
@@ -45,6 +45,9 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '7'
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,20 +55,23 @@ dependencies:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: '4'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '7'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: armitage-rubocop
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '0.77'
67
+ version: '0.78'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '0.77'
74
+ version: '0.78'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: rspec
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +107,9 @@ dependencies:
101
107
  - - ">="
102
108
  - !ruby/object:Gem::Version
103
109
  version: '5'
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '7'
104
113
  type: :development
105
114
  prerelease: false
106
115
  version_requirements: !ruby/object:Gem::Requirement
@@ -108,6 +117,9 @@ dependencies:
108
117
  - - ">="
109
118
  - !ruby/object:Gem::Version
110
119
  version: '5'
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '7'
111
123
  - !ruby/object:Gem::Dependency
112
124
  name: timecop
113
125
  requirement: !ruby/object:Gem::Requirement
@@ -126,46 +138,46 @@ dependencies:
126
138
  name: bundler
127
139
  requirement: !ruby/object:Gem::Requirement
128
140
  requirements:
129
- - - ">="
141
+ - - "~>"
130
142
  - !ruby/object:Gem::Version
131
- version: '0'
143
+ version: '2.1'
132
144
  type: :development
133
145
  prerelease: false
134
146
  version_requirements: !ruby/object:Gem::Requirement
135
147
  requirements:
136
- - - ">="
148
+ - - "~>"
137
149
  - !ruby/object:Gem::Version
138
- version: '0'
150
+ version: '2.1'
139
151
  - !ruby/object:Gem::Dependency
140
152
  name: rake
141
153
  requirement: !ruby/object:Gem::Requirement
142
154
  requirements:
143
- - - ">="
155
+ - - "~>"
144
156
  - !ruby/object:Gem::Version
145
- version: '0'
157
+ version: '13.0'
146
158
  type: :development
147
159
  prerelease: false
148
160
  version_requirements: !ruby/object:Gem::Requirement
149
161
  requirements:
150
- - - ">="
162
+ - - "~>"
151
163
  - !ruby/object:Gem::Version
152
- version: '0'
164
+ version: '13.0'
153
165
  - !ruby/object:Gem::Dependency
154
166
  name: pry
155
167
  requirement: !ruby/object:Gem::Requirement
156
168
  requirements:
157
- - - ">="
169
+ - - "~>"
158
170
  - !ruby/object:Gem::Version
159
- version: '0'
171
+ version: '0.12'
160
172
  type: :development
161
173
  prerelease: false
162
174
  version_requirements: !ruby/object:Gem::Requirement
163
175
  requirements:
164
- - - ">="
176
+ - - "~>"
165
177
  - !ruby/object:Gem::Version
166
- version: '0'
167
- description: Sidekiq::Portal - emulate job activity in tests when you work with time
168
- traveling.
178
+ version: '0.12'
179
+ description: Sidekiq::Portal - emulate scheduled job activity in tests when you work
180
+ with time traveling.
169
181
  email:
170
182
  - iamdaiver@icloud.com
171
183
  executables: []
@@ -225,8 +237,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
237
  - !ruby/object:Gem::Version
226
238
  version: '0'
227
239
  requirements: []
228
- rubygems_version: 3.0.3
240
+ rubygems_version: 3.1.2
229
241
  signing_key:
230
242
  specification_version: 4
231
- summary: Sidekiq::Portal - emulate job activity in tests when you work with time traveling.
243
+ summary: Sidekiq::Portal - scheduled jobs invocation emulation for test environments
232
244
  test_files: []