Skip to content

Commit

Permalink
README fix and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
gzigzigzeo committed Nov 27, 2018
1 parent 604b62a commit 83fe59c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ This jobs will be grouped into the single job with the single argument:
# => [[5]]
```

- `tests_env` is used to check about test environment for `force_flush_for_test!` method (check "Testing with Sidekiq::Testing.fake!" section)
- `tests_env` is used to silence some logging in test environments (see below). Default: true if `Rails.env.test?`, false otherwise.

## Web UI

Expand Down Expand Up @@ -146,7 +146,9 @@ Note that you should set poll_interval option inside of sidekiq.yml to take effe

## Testing with Sidekiq::Testing.fake!

Sidekiq::Grouping is using separate queues for grouping tasks, so you need manualy "group" tasks in your tests, if you want check tasks in your tests by sidekiq fake interface. For this case exists function `Sidekiq::Grouping.force_flush_for_test!`. Example:
Sidekiq::Grouping uses internal queues for grouping tasks. If you need to force flush internal queues into normal Sidekiq queues, use `Sidekiq::Grouping.force_flush_for_test!`.

See example:

```ruby
# worker
Expand All @@ -163,7 +165,7 @@ class GroupedWorker
)

def perform(grouped_arguments)
# your code
# ... important payload
end

end
Expand All @@ -178,7 +180,9 @@ RSpec.describe GroupedWorker, type: :worker do
described_class.perform_async(1)
described_class.perform_async(2)
described_class.perform_async(2)
Sidekiq::Grouping.force_flush_for_test! # call this to flush job in queue

# All 4 above asks will be put to :custom_queue despite of :batch_flush_size is set to 9.
Sidekiq::Grouping.force_flush_for_test!

last_job = described_class.jobs.last
expect(last_job['args']).to eq([[[1], [2]]])
Expand All @@ -191,12 +195,6 @@ end

```

If environment is not for tests (default value is `Rails.env.test`), then you will get warning message about usage this method in incorrect way. You can override check for test environment by `tests_env` option.

## TODO

1. Add support redis_pool option.

## Installation

Add this line to your application's Gemfile:
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/grouping/flusher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def flush_concrete(batches)
names = batches.map { |batch| "#{batch.worker_class} in #{batch.queue}" }
Sidekiq::Grouping.logger.info(
"[Sidekiq::Grouping] Trying to flush batched queues: #{names.join(',')}"
) unless defined?(::Rails) && Rails.respond_to?(:env) && Rails.env.test?
) unless Sidekiq::Grouping::Config.tests_env
batches.each(&:flush)
end
end
2 changes: 1 addition & 1 deletion lib/sidekiq/grouping/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Sidekiq
module Grouping
VERSION = "1.0.9 "
VERSION = "1.0.10"
end
end

0 comments on commit 83fe59c

Please sign in to comment.