Skip to content
Snippets Groups Projects
Commit a158e1a8 authored by baldwinlouie's avatar baldwinlouie Committed by Yas Naoi
Browse files

Issue #3278867 by baldwinlouie, yas: Add a queue garbage collection cron job

parent cb6e7743
Branches
Tags
3 merge requests!1316Issue #3310263: Release 4.5.0,!1260Issue #3307397: Release 4.4.0,!907Issue #3278867: Add a queue garbage collection cron job
......@@ -1255,3 +1255,13 @@ function cloud_update_8157(): void {
drupal_flush_all_caches();
}
/**
* Add cloud_enable_queue_cleanup flag to configuration.
*/
function cloud_update_8158(): void {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('cloud.settings');
$config->set('cloud_enable_queue_cleanup', TRUE);
$config->save();
}
......@@ -46,6 +46,21 @@ if (!function_exists('str_contains')) {
}
/**
* Implements hook_cron().
*/
function cloud_cron() {
$config = \Drupal::config('cloud.settings');
if ($config->get('cloud_enable_queue_cleanup') === TRUE) {
// Clean out batch items older than 1 day.
\Drupal::database()
->delete('queue')
->condition('created', time() - 86400, '<')
->condition('name', 'drupal_batch:%', 'LIKE')
->execute();
}
}
/**
* Implements hook_help().
*/
......
......@@ -12,3 +12,4 @@ cloud_custom_datatables_js_url: 'https://cdn.jsdelivr.net/npm/simple-datatables@
cloud_use_default_urls: '1'
cloud_view_items_per_page: 50
cloud_view_expose_items_per_page: true
cloud_enable_queue_cleanup: true
......@@ -29,3 +29,5 @@ cloud.settings:
type: integer
cloud_view_expose_items_per_page:
type: boolean
cloud_enable_queue_cleanup:
type: boolean
......@@ -268,6 +268,18 @@ class CloudAdminSettings extends ConfigFormBase {
'#default_value' => $config->get('cloud_view_items_per_page'),
];
$form['queue'] = [
'#type' => 'details',
'#title' => $this->t('Queue'),
'#open' => TRUE,
];
$form['queue']['cloud_enable_queue_cleanup'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable queue cleanup'),
'#description' => $this->t('Clean up orphaned and failed batch items in the queue table. Items older than one day are deleted.'),
'#default_value' => $config->get('cloud_enable_queue_cleanup'),
];
return parent::buildForm($form, $form_state);
}
......@@ -326,6 +338,7 @@ class CloudAdminSettings extends ConfigFormBase {
if ($this->moduleHandler->moduleExists('geocoder')) {
$config->set('cloud_location_geocoder_plugin', $form_state->getValue('cloud_location_geocoder_plugin'));
}
$config->set('cloud_enable_queue_cleanup', $form_state->getValue('cloud_enable_queue_cleanup'));
$config->save();
$views_settings = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment