batch_queue 0.1.0 → 1.0.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
  SHA1:
3
- metadata.gz: 2b95fc0b74f01e311f6054edca52d5e914caeb0e
4
- data.tar.gz: 4698c96901a2a66c2b8f7a61b960fc3b87097da5
3
+ metadata.gz: df6a825858badbbd444159c27bc643efb4ba2f7d
4
+ data.tar.gz: 11d1abe1d25b45733767e0f884bcb23a353607f4
5
5
  SHA512:
6
- metadata.gz: def8c8a4612de2b9bc4d4e484a20ab0e500391b5c98a33056001710019c86cfe2c55159248b44873cccd8e370e762b21fc9796c75f3020d65e28e239d4a1ae0f
7
- data.tar.gz: b00f65b31ef402135eb2f0630878e80cd66a1d2e4eab4cc5d36efbbee6e71d0d6aafe55402c7f49b1f8f6ab900283341bd7dad66adde2febc86ed556dacd98ca
6
+ metadata.gz: 2f48dca2b314320eb441901bbc7264575fab419dc381c6bce1711f7bc04696919fb0dd98f582413dcedbaa63a0b37224b9ea4253aaf576c989503eee360133ba
7
+ data.tar.gz: a4c4d1ca28b61019d1242a0c8b3b0c58134692cac09ed53e67ee8c3b8a9ba48e923fb34cf036b46456e955fcc645fbc1fbe9faa1326f8a4e96464f28284cf686
data/README.md CHANGED
@@ -1,8 +1,24 @@
1
1
  # BatchQueue
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/batch_queue`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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:
6
+
7
+ ```
8
+ # Create the AWS CloudWatch Client
9
+ cw_client = Aws::CloudWatch::Client.new(...)
10
+
11
+ # Set up the BatchQueue
12
+ BatchQueue.new(max_batch_size: 20, max_interval_seconds: 60) do |batch_metric_data|
13
+ cw_client.put_metric_data(:metric_data => batch_metric_data)
14
+ end
15
+
16
+ # Add to the BatchQueue
17
+ @bq << {
18
+ metric_name: 'Widgets',
19
+ value: 1
20
+ }
21
+ ```
6
22
 
7
23
  ## Installation
8
24
 
@@ -22,7 +38,28 @@ Or install it yourself as:
22
38
 
23
39
  ## Usage
24
40
 
25
- TODO: Write usage instructions here
41
+ ### 1. Set up the BatchQueue
42
+ Each BatchQueue gets its own background thread that executes jobs.
43
+ ```
44
+ bq = BatchQueue.new(max_batch_size: 20, max_interval_seconds: 60) do |batch_metric_data|
45
+ # Put your code that you want to execute here.
46
+ end
47
+ ```
48
+
49
+ ### 2. Add a job to the queue
50
+ You can add any object to the queue.
51
+ ```
52
+ bq << {
53
+ # your object here.
54
+ }
55
+
56
+ ```
57
+ or
58
+ ```
59
+ bq << MyJob.new(...)
60
+
61
+ ```
62
+
26
63
 
27
64
  ## Development
28
65
 
@@ -32,7 +69,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
69
 
33
70
  ## Contributing
34
71
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/batch_queue.
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/flivni/batch_queue.
36
73
 
37
74
  ## License
38
75
 
@@ -19,11 +19,6 @@ class BatchQueue
19
19
  end
20
20
  end
21
21
 
22
- # a block taking taking an exception as a parameter
23
- def on_error(&block)
24
- @on_error = block
25
- end
26
-
27
22
  def push(object)
28
23
  @mutex.synchronize do
29
24
  raise 'BatchQueue is stopped' unless @is_running
@@ -87,7 +82,7 @@ class BatchQueue
87
82
  begin
88
83
  @block.call(arr)
89
84
  rescue StandardError => exc
90
- @on_error.call(exc) if @on_error
85
+ puts "BatchQueue: Unhandled exception #{exc.inspect}"
91
86
  ensure
92
87
  @mutex.lock
93
88
  end
@@ -1,3 +1,3 @@
1
1
  class BatchQueue
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.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: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Livni
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-16 00:00:00.000000000 Z
11
+ date: 2019-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler