[Improved] Logic

This commit is contained in:
Neozonz 2014-01-21 22:03:14 -05:00
parent d278e99172
commit c91bb682af

View File

@ -148,60 +148,61 @@ if (!$setting->setValue('pps_last_share_id', $iLastShareId)) {
// Fetch all unaccounted blocks // Fetch all unaccounted blocks
$log->logInfo("\tFetching unaccounted blocks."); $log->logInfo("\tFetching unaccounted blocks.");
if (!$aAllBlocks = $block->getAllUnaccounted('ASC')) { if ($aAllBlocks = $block->getAllUnaccounted('ASC')) {
$log->logInfo("Failed to fetch unaccounted Blocks. NOTICE: " . $block->getCronError()); // Go through blocks and archive/delete shares that have been accounted for
} foreach ($aAllBlocks as $iIndex => $aBlock) {
if (empty($aAllBlocks)) { // If we are running through more than one block, check for previous share ID
$log->logInfo("\tNo new blocks."); $log->logInfo("\tProcess each block for Previous Share ID.");
// No monitoring event here, not fatal for PPS $iLastBlockShare = @$aAllBlocks[$iIndex - 1]['share_id'] ? @$aAllBlocks[$iIndex - 1]['share_id'] : 0;
} if (!is_numeric($aBlock['share_id'])) {
$log->logFatal("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue");
// Go through blocks and archive/delete shares that have been accounted for $monitoring->setStatus($cron_name . "_active", "yesno", 0);
foreach ($aAllBlocks as $iIndex => $aBlock) { $monitoring->setStatus($cron_name . "_message", "message", "Block " . $aBlock['height'] . " has no share_id associated with it");
// If we are running through more than one block, check for previous share ID $monitoring->setStatus($cron_name . "_status", "okerror", 1);
$log->logInfo("\tProcess each block for Previous Share ID."); exit(1);
$iLastBlockShare = @$aAllBlocks[$iIndex - 1]['share_id'] ? @$aAllBlocks[$iIndex - 1]['share_id'] : 0; }
if (!is_numeric($aBlock['share_id'])) { // Per account statistics
$log->logFatal("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue"); $log->logInfo("\tRefresh user statistics...");
$monitoring->setStatus($cron_name . "_active", "yesno", 0); if (!$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id'])) {
$monitoring->setStatus($cron_name . "_message", "message", "Block " . $aBlock['height'] . " has no share_id associated with it"); $log->logError("Failed to Account Shares. ERROR: " . $share->getCronError());
$monitoring->setStatus($cron_name . "_status", "okerror", 1); }
exit(1); foreach ($aAccountShares as $key => $aData) {
} if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
// Per account statistics $log->logError("Failed to update statistics for Block " . $aBlock['id'] . "for" . $aData['username'] . ' ERROR: ' . $statistics->getCronError());
$log->logInfo("\tRefresh user statistics..."); }
if (!$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id'])) { $log->logInfo("\Statistics updated.");
$log->logError("Failed to Account Shares. ERROR: " . $share->getCronError());
}
foreach ($aAccountShares as $key => $aData) {
if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
$log->logError("Failed to update statistics for Block " . $aBlock['id'] . "for" . $aData['username'] . ' ERROR: ' . $statistics->getCronError());
}
$log->logInfo("\Statistics updated.");
// Move shares to archive // Move shares to archive
$log->logInfo("\t$aBlock['id']\t Move shares to archive..."); $log->logInfo("\t$aBlock['id']\t Move shares to archive...");
if ($aBlock['share_id'] < $iLastShareId) { if ($aBlock['share_id'] < $iLastShareId) {
if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare)) if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare))
$log->logError("Failed to copy shares to from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ' Error: ' . $share->getCronError()); $log->logError("Failed to copy shares to from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ' Error: ' . $share->getCronError());
} }
$log->logInfo("\t$aBlock['id']\t Shares moved to archive..."); $log->logInfo("\t$aBlock['id']\t Shares moved to archive...");
// Delete shares // Delete shares
$log->logInfo("\t$aBlock['id']\t Deleting accounted shares..."); $log->logInfo("\t$aBlock['id']\t Deleting accounted shares...");
if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) { if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) {
$log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getCronError()); $log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getCronError());
$monitoring->endCronjob($cron_name, 'E0016', 1, true); $monitoring->endCronjob($cron_name, 'E0016', 1, true);
} }
$log->logInfo("\t$aBlock['id']\t Deleted accounted shares."); $log->logInfo("\t$aBlock['id']\t Deleted accounted shares.");
// Mark this block as accounted for // Mark this block as accounted for
$log->logInfo("\t$aBlock['id']\t Marking Block as accounted..."); $log->logInfo("\t$aBlock['id']\t Marking Block as accounted...");
if (!$block->setAccounted($aBlock['id'])) { if (!$block->setAccounted($aBlock['id'])) {
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError()); $log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError());
$monitoring->endCronjob($cron_name, 'E0014', 1, true); $monitoring->endCronjob($cron_name, 'E0014', 1, true);
} }
$log->logInfo("\t$aBlock['id']\t Block paid and accounted for."); $log->logInfo("\t$aBlock['id']\t Block paid and accounted for.");
}
}
else if (empty($aAllBlocks)) {
$log->logInfo("\tNo new blocks.");
// No monitoring event here, not fatal for PPS
}
else {
$log->logInfo("Failed to fetch unaccounted Blocks. NOTICE: " . $block->getCronError());
} }
$log->logInfo("Completed PPS Payout"); $log->logInfo("Completed PPS Payout");