Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify drain_all to respect enqueued order #3418

Closed
wants to merge 1 commit into from

Conversation

ggilder
Copy link

@ggilder ggilder commented Apr 4, 2017

Currently Sidekiq::Worker.drain_all effectively reorders the queue by
grouping job classes together. This change maintains the enqueued order
of jobs in the queue when using drain_all.

Currently `Sidekiq::Worker.drain_all` effectively reorders the queue by
grouping job classes together. This change maintains the enqueued order
of jobs in the queue when using `drain_all`.
@mperham
Copy link
Collaborator

mperham commented Apr 4, 2017

It is a smell to depend on execution ordering in an async system.

@ggilder
Copy link
Author

ggilder commented Apr 4, 2017

I agree in principle, but you already have deterministic ordering here — it's just not the natural ordering that jobs were enqueued in.

@mperham
Copy link
Collaborator

mperham commented Apr 4, 2017 via email

@ggilder
Copy link
Author

ggilder commented Apr 4, 2017

Haha... ok, so maybe to make this more concrete I can present the problem that led me to stumble on this.

I have an app where I use Cucumber scenarios to test complex flows. They make fairly heavy use of tables to concisely document the state of the database before and after certain actions are performed, so something like this simplified example:

Then expect the incidents table to contain:
  | id  | source | case_id | state       | amount |
  | 801 | abc01  | 10001   | active_case | 4000   |
  | 802 | abc01  | 10002   | active_case | 1600   |
  | 803 | abc02  | 10003   | active_case | 1600   |
  | 804 | abc02  | 10004   | active_case | 2300   |

So there's an implicit assumption that associated models (in this example, cases and incidents) are created in order because we enqueue jobs that process each incident in order.

Now, you could certainly rewrite that to not specify the foreign key ids, but it would be much more cumbersome. So from my perspective, maintaining the queue order is a convenience that allows my test scenarios to be simpler and easier to maintain.

If this is not something you want to support in sidekiq, that's fine... just thought I'd give some context in case that sways you at all. :)

@mperham
Copy link
Collaborator

mperham commented Apr 4, 2017

You can assert the ID is non-nil, you can assert it is within a range but I still maintain it's a bad idea to depend on precise code ordering within your integration tests unless you explicitly execute the code yourself.

@mperham mperham closed this Apr 4, 2017
@ggilder ggilder deleted the testing-drain-jobs-in-order branch April 4, 2017 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants