[Improved] Logic
This commit is contained in:
parent
d278e99172
commit
c91bb682af
@ -148,60 +148,61 @@ if (!$setting->setValue('pps_last_share_id', $iLastShareId)) {
|
||||
|
||||
// Fetch all unaccounted blocks
|
||||
$log->logInfo("\tFetching unaccounted blocks.");
|
||||
if (!$aAllBlocks = $block->getAllUnaccounted('ASC')) {
|
||||
$log->logInfo("Failed to fetch unaccounted Blocks. NOTICE: " . $block->getCronError());
|
||||
}
|
||||
if (empty($aAllBlocks)) {
|
||||
$log->logInfo("\tNo new blocks.");
|
||||
// No monitoring event here, not fatal for PPS
|
||||
}
|
||||
|
||||
// Go through blocks and archive/delete shares that have been accounted for
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// If we are running through more than one block, check for previous share ID
|
||||
$log->logInfo("\tProcess each block for Previous Share ID.");
|
||||
$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");
|
||||
$monitoring->setStatus($cron_name . "_active", "yesno", 0);
|
||||
$monitoring->setStatus($cron_name . "_message", "message", "Block " . $aBlock['height'] . " has no share_id associated with it");
|
||||
$monitoring->setStatus($cron_name . "_status", "okerror", 1);
|
||||
exit(1);
|
||||
}
|
||||
// Per account statistics
|
||||
$log->logInfo("\tRefresh user statistics...");
|
||||
if (!$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id'])) {
|
||||
$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.");
|
||||
if ($aAllBlocks = $block->getAllUnaccounted('ASC')) {
|
||||
// Go through blocks and archive/delete shares that have been accounted for
|
||||
foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// If we are running through more than one block, check for previous share ID
|
||||
$log->logInfo("\tProcess each block for Previous Share ID.");
|
||||
$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");
|
||||
$monitoring->setStatus($cron_name . "_active", "yesno", 0);
|
||||
$monitoring->setStatus($cron_name . "_message", "message", "Block " . $aBlock['height'] . " has no share_id associated with it");
|
||||
$monitoring->setStatus($cron_name . "_status", "okerror", 1);
|
||||
exit(1);
|
||||
}
|
||||
// Per account statistics
|
||||
$log->logInfo("\tRefresh user statistics...");
|
||||
if (!$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id'])) {
|
||||
$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
|
||||
$log->logInfo("\t$aBlock['id']\t Move shares to archive...");
|
||||
if ($aBlock['share_id'] < $iLastShareId) {
|
||||
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->logInfo("\t$aBlock['id']\t Shares moved to archive...");
|
||||
// Move shares to archive
|
||||
$log->logInfo("\t$aBlock['id']\t Move shares to archive...");
|
||||
if ($aBlock['share_id'] < $iLastShareId) {
|
||||
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->logInfo("\t$aBlock['id']\t Shares moved to archive...");
|
||||
|
||||
// Delete shares
|
||||
$log->logInfo("\t$aBlock['id']\t Deleting accounted shares...");
|
||||
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());
|
||||
$monitoring->endCronjob($cron_name, 'E0016', 1, true);
|
||||
}
|
||||
$log->logInfo("\t$aBlock['id']\t Deleted accounted shares.");
|
||||
// Delete shares
|
||||
$log->logInfo("\t$aBlock['id']\t Deleting accounted shares...");
|
||||
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());
|
||||
$monitoring->endCronjob($cron_name, 'E0016', 1, true);
|
||||
}
|
||||
$log->logInfo("\t$aBlock['id']\t Deleted accounted shares.");
|
||||
|
||||
// Mark this block as accounted for
|
||||
$log->logInfo("\t$aBlock['id']\t Marking Block as accounted...");
|
||||
if (!$block->setAccounted($aBlock['id'])) {
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0014', 1, true);
|
||||
}
|
||||
$log->logInfo("\t$aBlock['id']\t Block paid and accounted for.");
|
||||
// Mark this block as accounted for
|
||||
$log->logInfo("\t$aBlock['id']\t Marking Block as accounted...");
|
||||
if (!$block->setAccounted($aBlock['id'])) {
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0014', 1, true);
|
||||
}
|
||||
$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");
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user