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

Feature request: job priority #56

Closed
KushalP opened this issue Mar 25, 2019 · 5 comments · Fixed by #65
Closed

Feature request: job priority #56

KushalP opened this issue Mar 25, 2019 · 5 comments · Fixed by #65

Comments

@KushalP
Copy link
Contributor

KushalP commented Mar 25, 2019

Summary

All jobs are not created equal. Some need to be scheduled earlier than others if there aren't enough workers to work on all of the enqueued jobs. Allow defining a priority against all jobs to make sure that higher priority jobs are scheduled.

An example

You are running a subscription business and have two background jobs defined:

  • sending a webhook to Slack to notify your team of a new subscriber
  • sending an email to the customer confirming their order to them

In this example you want to send the email to the customer to make sure they have feedback on the receipt of their subscription. This would take a higher priority over notifying a Slack channel.

Design idea

Create a column priority (smallint/integer) that allows defining an integer priority. This can conform to the niceness values used in Linux — lower values are more important. When trying to poll for jobs, order the result by priority.

@samsondav
Copy link
Owner

@KushalP Thanks for opening this issue!

Yup, the idea sounds good. Shouldn't be too hard. We're going to need a migration since we have to add a column and either add/modify an index to cover priority.

Would you like to take a crack at implementing this?

@KushalP
Copy link
Contributor Author

KushalP commented Mar 25, 2019

Makes sense. How should the priority be defined on a Rihanna.Job level for people implementing their own priority levels?

@samsondav
Copy link
Owner

You asked for the feature... how would you like to use it? :)

@KushalP
Copy link
Contributor Author

KushalP commented Mar 25, 2019

A field that could be overridden makes sense: @priorty 10.

@samsondav
Copy link
Owner

Sounds great. Could be even better as a function:

def priority, do: 10

This has two advantages:

  1. It can be defined in the behaviour as an optional (or overridable) callback
  2. It can be calculated dynamically if the client really wants to implement that

KushalP added a commit to KushalP/rihanna that referenced this issue Mar 25, 2019
…amsondav#56]

This allows developers to define their own priorities for jobs.
tpitale pushed a commit to tpitale/rihanna that referenced this issue Jun 3, 2019
…amsondav#56]

This allows developers to define their own priorities for jobs.
@tpitale tpitale mentioned this issue Jun 3, 2019
tpitale pushed a commit to tpitale/rihanna that referenced this issue Jul 22, 2019
…amsondav#56]

This allows developers to define their own priorities for jobs.
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 a pull request may close this issue.

2 participants