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

[8.x] Add command to clean batches table #35694

Merged
merged 5 commits into from Dec 24, 2020
Merged

[8.x] Add command to clean batches table #35694

merged 5 commits into from Dec 24, 2020

Conversation

dmason30
Copy link
Contributor

@dmason30 dmason30 commented Dec 22, 2020

Provides a queue:prune-batches command for cleaning the job_batches table added in 8.x.

>>> php artisan queue:prune-batches
199 entries deleted.

Heavily inspired by the telescope:prune command this change is almost an exact copy of that.
https://github.com/laravel/telescope/blob/master/src/Console/PruneCommand.php

It has an --hours optional argument that defaults to 24 and it uses the finished_at column to do the date comparison.

Similarly to telescope it can easily be put into the scheduler:

$schedule->command('queue:prune-batches --hours=48')->daily();

None of the queue commands currently have tests so I haven't added any for this one.

If you want me to add tests please do let me know.

@dmason30 dmason30 changed the title Batch flush Add command to clean batches table Dec 22, 2020
@dmason30 dmason30 changed the title Add command to clean batches table [8.x] Add command to clean batches table Dec 22, 2020
@taylorotwell
Copy link
Member

I'm not sure if "flush-batch" is the right word? That makes me think all of the table's records will be deleted when really it's just pruning existing ones.

@dmason30
Copy link
Contributor Author

dmason30 commented Dec 22, 2020

@taylorotwell I agree, As I mentioned in the OP prune is the correct term but its not something that has been used anywhere else in core. If you want I can change class names and command signature to use prune instead. The new command would be queue:prune-batch ?

@taylorotwell
Copy link
Member

I would likely call it something like queue:prune-batches

@dmason30
Copy link
Contributor Author

Pushed change to queue:prune-batches as discussed.

@taylorotwell taylorotwell merged commit 8dc4425 into laravel:8.x Dec 24, 2020
/**
* Prune all of the entries older than the given date.
*
* @param DateTimeInterface $before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing slash

/**
* Prune all of the entries older than the given date.
*
* @param DateTimeInterface $before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing slash

$totalDeleted = 0;

do {
$deleted = $query->take(1000)->delete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you just use the query builder's each function?

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.

None yet

4 participants