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 +4 -4
- data/README.md +41 -4
- data/lib/batch_queue/batch_queue.rb +1 -6
- data/lib/batch_queue/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df6a825858badbbd444159c27bc643efb4ba2f7d
|
4
|
+
data.tar.gz: 11d1abe1d25b45733767e0f884bcb23a353607f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f48dca2b314320eb441901bbc7264575fab419dc381c6bce1711f7bc04696919fb0dd98f582413dcedbaa63a0b37224b9ea4253aaf576c989503eee360133ba
|
7
|
+
data.tar.gz: a4c4d1ca28b61019d1242a0c8b3b0c58134692cac09ed53e67ee8c3b8a9ba48e923fb34cf036b46456e955fcc645fbc1fbe9faa1326f8a4e96464f28284cf686
|
data/README.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
# BatchQueue
|
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
|
-
|
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
|
-
|
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/
|
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
|
-
|
85
|
+
puts "BatchQueue: Unhandled exception #{exc.inspect}"
|
91
86
|
ensure
|
92
87
|
@mutex.lock
|
93
88
|
end
|
data/lib/batch_queue/version.rb
CHANGED
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:
|
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-
|
11
|
+
date: 2019-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|