Skip to content

Commit

Permalink
Merge pull request MPOS#1764 from MPOS/combine-cleanups
Browse files Browse the repository at this point in the history
[IMPROVED] Combined cleanup tasks into single PHP
  • Loading branch information
TheSerapher committed Feb 16, 2014
2 parents e6a396c + 146b562 commit 5c22cc3
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 119 deletions.
39 changes: 0 additions & 39 deletions cronjobs/archive_cleanup.php

This file was deleted.

38 changes: 0 additions & 38 deletions cronjobs/notification_cleanup.php

This file was deleted.

2 changes: 1 addition & 1 deletion cronjobs/run-crons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cronjobs/run-maintenance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
79 changes: 79 additions & 0 deletions cronjobs/tables_cleanup.php
Original file line number Diff line number Diff line change
@@ -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');
?>
39 changes: 0 additions & 39 deletions cronjobs/token_cleanup.php

This file was deleted.

2 changes: 1 addition & 1 deletion public/include/config/monitor_crons.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 5c22cc3

Please sign in to comment.