batch_queue 1.0.0 → 1.1.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
- SHA1:
3
- metadata.gz: df6a825858badbbd444159c27bc643efb4ba2f7d
4
- data.tar.gz: 11d1abe1d25b45733767e0f884bcb23a353607f4
2
+ SHA256:
3
+ metadata.gz: 3b0f824265dd97a0c9992e49bb276d1131a79851ee6392c477941aa2c34261f4
4
+ data.tar.gz: 3f4067e301015ee56ba0263d8da5ef79b5b2a897bac6ffc863e14b31a5fdd4b9
5
5
  SHA512:
6
- metadata.gz: 2f48dca2b314320eb441901bbc7264575fab419dc381c6bce1711f7bc04696919fb0dd98f582413dcedbaa63a0b37224b9ea4253aaf576c989503eee360133ba
7
- data.tar.gz: a4c4d1ca28b61019d1242a0c8b3b0c58134692cac09ed53e67ee8c3b8a9ba48e923fb34cf036b46456e955fcc645fbc1fbe9faa1326f8a4e96464f28284cf686
6
+ metadata.gz: eab99b1882c61b1ae01d68ece1680e055f5818e979869c6bd9f38e505f388e1768350468c8ac344326c5d7baf96968bd61bd3f74abaad144f3563f8c449e515d
7
+ data.tar.gz: 5101491e33aca1f85e1d614ff6dabe3c825b68cc131164dbf4f4cc43074ee17aeb2868d26e62645aa6a617395e50a42d8834fe65d21274a690d0fab11bf7708f
@@ -0,0 +1,18 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest, macos-latest]
9
+ # Could consider adding head, jruby-head, jruby in the future
10
+ ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', truffleruby, truffleruby-head]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
18
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -7,4 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /batch_queue-0.1.0.gem
10
+ /batch_queue-*.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [1.1.0] - 2024-11-03
2
+ ### Added
3
+ - Support for error handling
4
+ - attr_readers for `max_batch_size` and `max_interval_seconds`
5
+ - update to support more recent minitest
6
+
7
+ ## [1.0.0] - 2019-09-01
8
+ ### Added
9
+ - Initial release of the gem.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- batch_queue (0.1.0)
4
+ batch_queue (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -14,18 +14,19 @@ GEM
14
14
  builder
15
15
  minitest (>= 5.0)
16
16
  ruby-progressbar
17
- rake (10.5.0)
17
+ rake (13.0.1)
18
18
  ruby-progressbar (1.10.0)
19
19
 
20
20
  PLATFORMS
21
21
  ruby
22
+ universal-darwin-24
22
23
 
23
24
  DEPENDENCIES
24
25
  batch_queue!
25
- bundler (~> 1.16)
26
+ bundler (~> 2.2)
26
27
  minitest (~> 5.0)
27
28
  minitest-reporters (~> 1.4)
28
- rake (~> 10.0)
29
+ rake (~> 13.0)
29
30
 
30
31
  BUNDLED WITH
31
- 1.16.2
32
+ 2.3.26
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  BatchQueue is queue that takes jobs and runs them, in aggregate, via a callback on a background thread. You can process a “batch” of N jobs at a time or after T seconds whichever comes sooner.
4
4
 
5
- Example: You want to send metrics to Amazon’s AWS CloudWatch service every 60 seconds or when the batch size reaches 20, whichever comes first. You might write code like this:
5
+ ## Example
6
+ You want to send metrics to Amazon’s AWS CloudWatch service every 60 seconds or when the batch size reaches 20, whichever comes first. You might write code like this:
6
7
 
7
8
  ```
8
9
  # Create the AWS CloudWatch Client
@@ -59,7 +60,30 @@ or
59
60
  bq << MyJob.new(...)
60
61
 
61
62
  ```
63
+ ### 3. Error handling
64
+ You have two options for handling errors in `BatchQueue`:
62
65
 
66
+ * Rescue exceptions within the processing block:
67
+
68
+ ```
69
+ bq = BatchQueue.new(max_batch_size: 20, max_interval_seconds: 60) do |batch_metric_data|
70
+ begin
71
+ # Put your code that you want to execute here.
72
+ rescue => e
73
+ # Handle the exception here.
74
+ end
75
+ end
76
+
77
+ ```
78
+
79
+ * Set a global error handler:
80
+
81
+ ```
82
+ bq.on_error = ->(e) { puts e.message }
83
+ ```
84
+
85
+ If neither method is used, `BatchQueue` will catch the exception and print it to
86
+ the standard console output.
63
87
 
64
88
  ## Development
65
89
 
data/batch_queue.gemspec CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.16"
27
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "bundler", "~> 2.2"
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
28
  spec.add_development_dependency "minitest", "~> 5.0"
29
29
  spec.add_development_dependency "minitest-reporters", '~> 1.4'
30
30
  end
@@ -1,4 +1,7 @@
1
1
  class BatchQueue
2
+ attr_reader :max_batch_size
3
+ attr_reader :max_interval_seconds
4
+
2
5
  # starts the queue
3
6
  # either max_batch_size or interval_milliseconds or both must be set
4
7
  def initialize(max_batch_size: nil, max_interval_seconds: nil, &block)
@@ -13,6 +16,7 @@ class BatchQueue
13
16
  @mutex = Mutex.new
14
17
  @cond_var = ConditionVariable.new
15
18
  @runner = Thread.new { run }
19
+ @on_error_callback = nil
16
20
 
17
21
  at_exit do
18
22
  stop
@@ -44,6 +48,10 @@ class BatchQueue
44
48
  @runner.join
45
49
  end
46
50
 
51
+ def on_error(&block)
52
+ @on_error_callback = block
53
+ end
54
+
47
55
  private
48
56
 
49
57
  def run
@@ -81,8 +89,12 @@ class BatchQueue
81
89
  @mutex.unlock
82
90
  begin
83
91
  @block.call(arr)
84
- rescue StandardError => exc
85
- puts "BatchQueue: Unhandled exception #{exc.inspect}"
92
+ rescue StandardError => e
93
+ if @on_error_callback
94
+ @on_error_callback.call(e)
95
+ else
96
+ puts "BatchQueue: Unhandled exception #{exc.inspect}"
97
+ end
86
98
  ensure
87
99
  @mutex.lock
88
100
  end
@@ -1,3 +1,3 @@
1
1
  class BatchQueue
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batch_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Livni
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2024-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,15 +66,17 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.4'
69
- description:
69
+ description:
70
70
  email:
71
71
  - flivni@gmail.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/workflows/ci.yml"
76
77
  - ".gitignore"
77
78
  - ".travis.yml"
79
+ - CHANGELOG.md
78
80
  - Gemfile
79
81
  - Gemfile.lock
80
82
  - LICENSE.txt
@@ -90,7 +92,7 @@ homepage: https://github.com/flivni/batch_queue
90
92
  licenses:
91
93
  - MIT
92
94
  metadata: {}
93
- post_install_message:
95
+ post_install_message:
94
96
  rdoc_options: []
95
97
  require_paths:
96
98
  - lib
@@ -105,9 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
107
  - !ruby/object:Gem::Version
106
108
  version: '0'
107
109
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.6.14
110
- signing_key:
110
+ rubygems_version: 3.3.27
111
+ signing_key:
111
112
  specification_version: 4
112
113
  summary: An in-memory queue that takes data and allows you to process it, in batches,
113
114
  on a background thread.