[IMPROVED] Combined cleanup tasks into single PHP

* [IMPROVED] Logging format for all cleanup tasks
* [UPDATED] Cron shellescripts
* [UPDATE] Cron Monitoring Page
* [DELETED] Old `*_cleanup.php` scripts
This commit is contained in:
Sebastian Grewe 2014-02-15 19:01:25 +01:00
parent 4cf1f35619
commit 146b56259b
7 changed files with 82 additions and 119 deletions

View File

@ -1,39 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// If we don't keep archives, delete some now to release disk space
$affected_rows = $share->purgeArchive();
if ($affected_rows === false) {
$log->logError("Failed to delete archived shares, not critical but should be checked: " . $share->getCronError());
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
} else {
$log->logDebug("Deleted $affected_rows archived shares this run");
}
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -1,38 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Cleanup old expired tokens
if ($notification->cleanupNotifications($setting->getValue('notifications_cleanup_time', 7))) {
$notification->deleted == 0 ? $log->logDebug('Did not delete any old notifications') : $log->logInfo('Deleted ' . $notification->deleted . ' notifications');
} else {
$log->logError('Failed to delete notifications: ' . $notification->getCronError());
$monitoring->endCronjob($cron_name, 'E0074', 0, false, false);
}
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -10,7 +10,7 @@
PHP_BIN=$( which php )
# List of cruns to execute
CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php token_cleanup.php archive_cleanup.php notification_cleanup.php"
CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php tables_cleanup.php"
# Output additional runtime information
VERBOSE="0"

View File

@ -10,7 +10,7 @@
PHP_BIN=$( which php )
# List of cruns to execute
CRONS="tickerupdate.php notifications.php token_cleanup.php archive_cleanup.php notification_cleanup.php"
CRONS="tickerupdate.php notifications.php tables_cleanup.php"
# Output additional runtime information
VERBOSE="0"

79
cronjobs/tables_cleanup.php Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Header
$strLogMask = "| %-20.20s | %10.10s | %8.8s | %6.6s | %-40s |";
$log->logInfo(sprintf($strLogMask, 'Process', 'Affected', 'Runtime', 'Status', 'Message'));
// Cleanup old notifications
$start = microtime(true);
$status = 'OK';
$message = '';
$affected = 0;
if ($notification->cleanupNotifications($setting->getValue('notifications_cleanup_time', 7))) {
$affected = $notification->deleted;
$affected == 0 ? $message = 'No notifications deleted' : $message = 'Deleted notifications older than ' . $setting->getValue('notifications_cleanup_time', 7) . ' days';
} else {
$message = 'Failed to delete notifications: ' . $notification->getCronError();
$status = 'ERROR';
$monitoring->endCronjob($cron_name, 'E0074', 0, false, false);
}
$log->logInfo(sprintf($strLogMask, 'cleanupNotifications', $affected, number_format(microtime(true) - $start, 3), $status, $message));
// Cleanup old expired tokens
$start = microtime(true);
$status = 'OK';
$message = '';
$affected = 0;
if ($oToken->cleanupTokens()) {
$affected = $oToken->deleted;
$affected == 0 ? $message = 'No tokens deleted' : $message = 'Deleted expired tokens';
} else {
$message = 'Failed to delete notifications: ' . $oToken->getCronError();
$status = 'ERROR';
$monitoring->endCronjob($cron_name, 'E0074', 0, false, false);
}
$log->logInfo(sprintf($strLogMask, 'cleanupTokens', $affected, number_format(microtime(true) - $start, 3), $status, $message));
// Clenaup shares archive
$start = microtime(true);
$status = 'OK';
$message = '';
$affected = $share->purgeArchive();
if ($affected === false) {
$message = 'Failed to delete notifications: ' . $oToken->getCronError();
$status = 'ERROR';
$monitoring->endCronjob($cron_name, 'E0008', 0, false, false);
} else {
$affected == 0 ? $message = 'No shares deleted' : $message = 'Deleted old shares';
}
$log->logInfo(sprintf($strLogMask, 'purgeArchive', $affected, number_format(microtime(true) - $start, 3), $status, $message));
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -1,39 +0,0 @@
#!/usr/bin/php
<?php
/*
Copyright:: 2013, Sebastian Grewe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Cleanup old expired tokens
if ($oToken->cleanupTokens()) {
$oToken->deleted == 0 ? $log->logDebug('Did not find any expired tokens') : $log->logInfo('Deleted ' . $oToken->deleted . ' expired tokens');
} else {
$log->logError('Failed to delete expired tokens: ' . $oToken->getCronError());
// Treat as critical since tokens like password resets will never expire
$monitoring->endCronjob($cron_name, 'E0074', 1, true, true);
}
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>

View File

@ -2,7 +2,7 @@
// Small helper array that may be used on some page controllers to
// fetch the crons we wish to monitor
$aMonitorCrons = array('statistics','payouts','token_cleanup','archive_cleanup','notification_cleanup','blockupdate','findblock','notifications','tickerupdate');
$aMonitorCrons = array('statistics','payouts','tables_cleanup','blockupdate','findblock','notifications','tickerupdate');
switch ($config['payout_system']) {
case 'pplns':