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

Batch enqueue #123

Open
kraih opened this issue Jan 1, 2023 · 2 comments
Open

Batch enqueue #123

kraih opened this issue Jan 1, 2023 · 2 comments

Comments

@kraih
Copy link
Member

kraih commented Jan 1, 2023

This came up in the Matrix channel. Apparently a few of our users would like to see support for batch enqueueing multiple jobs at once. Like in a database transaction. In this issue you can collect use cases to work out the exact requirements and maybe even the correct API.

But be aware that this has to work for all the databases and programming languages Minion supports.

@melo
Copy link

melo commented Jan 1, 2023

Hi,

I'll split the requirements into two items. I think this ticket is only for the first one.

  1. allow users to create multiple jobs in a single database transaction: either all of them are created or none are;
  2. allow Minion database access to be done inside an external-controlled transaction: this would allow users to (for example) get an API call to update our DB tables and then create a job to do some post-processing, all inside a single transaction. This assumes of course that the Minion tables share the main database.

I'll focus on the first item here.

The simplest API I can think off is a enqueue_batch() that takes a list of arrayRefs of parameters to the enqueue() API. Something like this would be enough:

my $arrayRefOfJobIds = $minion->batch_enqueue(
  [ ... enqueue parameters ... ],
  [ ... enqueue parameters ... ],
  [ ... enqueue parameters ... ],
  ...
);

An alternative is similar to karjala@matrix suggestion. We would take a codeRef and all calls to $minion->enqueue() inside that callback would be inside a single transaction. Like this:

$minion->tx(sub ($minion_tx, $db_tx) {
  # do other work on DB
  $db_tx->insert(...);

  # and queue multiple jobs
  $minion_tx->enqueue(....);
  $minion_tx->enqueue(....);
  $minion_tx->enqueue(....);
  ...
});

The advantage of this is that you can use the $db_tx handle to do other DB operations all of them inside the same transaction.

I think either of these is an options and both seem to be compatible with the three languages you mention.

Best regards.

Bye,

@akarelas
Copy link

akarelas commented Jan 1, 2023

I'm covered by @melo's comments.

For me it's very important that I am able to execute arbitrary SQL statements to my database, in the same transaction that enqueues minion jobs.

My use case is that I have to deduct credits from a user's account for adding a minion job, so these 2 things have to happen on the same transaction.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants