Issue #3580212: [Notifications] cron cleanup
Closes #3580212
- Adds automatic cleanup of stale and expired notifications via cron
- Stale processing notifications (older than 30 minutes) are purged and replaced with error notifications
- Expired notifications older than 30 days are deleted along with their associated read entries
Testing instructions
-
Create a stale processing notification (31m old)
ddev drush php-eval " \$handler = \Drupal::service(\Drupal\canvas\CanvasNotificationHandler::class); \$handler->create([ 'type' => 'processing', 'title' => 'Stale sync', 'message' => 'Syncing content...', 'key' => 'test-stale', 'timestamp' => (int)(microtime(TRUE) * 1000) - 1860000, ]); " -
Create an active processing notification
ddev drush php-eval " \$handler = \Drupal::service(\Drupal\canvas\CanvasNotificationHandler::class); \$handler->create([ 'type' => 'processing', 'title' => 'Recent sync', 'message' => 'Still going...', 'key' => 'test-recent', ]); " -
Create an expired notification (31 days old)
ddev drush php-eval " \$handler = \Drupal::service(\Drupal\canvas\CanvasNotificationHandler::class); \$handler->create([ 'type' => 'info', 'title' => 'Ancient notification', 'message' => 'From a month ago', 'key' => 'test-expired', 'timestamp' => (int)(microtime(TRUE) * 1000) - 2678400000, ]); " -
Verify all three were successfully created
ddev drush sqlq "SELECT * FROM canvas_notification ORDER BY timestamp DESC;" -
Run cron
ddev drush cron -
Fetch notifications
ddev drush sqlq "SELECT **id, type, title** FROM canvas_notification ORDER BY timestamp DESC;" - Verify that:
- The stale processing notification is gone, replaced by an error with title "Operation timed out", message "Syncing content...", and the same key as the processing notification it replaced
- The recent processing notification is still present and unchanged
- The expired info notification is gone
Edited by Sally Young