README.md in batch_queue-1.0.0 vs README.md in batch_queue-1.1.0
- old
+ new
@@ -1,10 +1,11 @@
# BatchQueue
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.
-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:
+## 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:
```
# Create the AWS CloudWatch Client
cw_client = Aws::CloudWatch::Client.new(...)
@@ -57,10 +58,33 @@
or
```
bq << MyJob.new(...)
```
+### 3. Error handling
+You have two options for handling errors in `BatchQueue`:
+* Rescue exceptions within the processing block:
+
+ ```
+ bq = BatchQueue.new(max_batch_size: 20, max_interval_seconds: 60) do |batch_metric_data|
+ begin
+ # Put your code that you want to execute here.
+ rescue => e
+ # Handle the exception here.
+ end
+ end
+
+ ```
+
+* Set a global error handler:
+
+ ```
+ bq.on_error = ->(e) { puts e.message }
+ ```
+
+If neither method is used, `BatchQueue` will catch the exception and print it to
+the standard console output.
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.