More verbose output on cron updates

* Added more verbosity to crons
* Made the output look better on consoles
* Added another error message to notifications class
This commit is contained in:
Sebastian Grewe 2013-06-24 10:36:59 +02:00
parent 71cb02c520
commit 2095b09d69
5 changed files with 65 additions and 30 deletions

View File

@ -22,8 +22,10 @@ limitations under the License.
// Include all settings and classes // Include all settings and classes
require_once('shared.inc.php'); require_once('shared.inc.php');
verbose("Running auto-payouts ...");
if ($bitcoin->can_connect() !== true) { if ($bitcoin->can_connect() !== true) {
verbose("Unable to connect to RPC server, exiting"); verbose(" unable to connect to RPC server, exiting\n");
exit(1); exit(1);
} }
@ -33,14 +35,17 @@ $setting->setValue('auto_payout_active', 1);
// Fetch all users with setup AP // Fetch all users with setup AP
$users = $user->getAllAutoPayout(); $users = $user->getAllAutoPayout();
// Quick summary
verbose(" found " . count($users) . " queued payout(s)\n");
// Go through users and run transactions // Go through users and run transactions
if (! empty($users)) { if (! empty($users)) {
verbose("UserID\tUsername\tBalance\tThreshold\tAddress\t\t\t\t\tStatus\n\n"); verbose("\tUserID\tUsername\tBalance\tThreshold\tAddress\t\t\t\t\tStatus\n\n");
foreach ($users as $aUserData) { foreach ($users as $aUserData) {
$aBalance = $transaction->getBalance($aUserData['id']); $aBalance = $transaction->getBalance($aUserData['id']);
$dBalance = $aBalance['confirmed']; $dBalance = $aBalance['confirmed'];
verbose($aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address'] . "\t"); verbose("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address'] . "\t");
// Only run if balance meets threshold and can pay the potential transaction fee // Only run if balance meets threshold and can pay the potential transaction fee
if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee']) { if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee']) {
@ -80,7 +85,7 @@ if (! empty($users)) {
} }
} }
} else { } else {
verbose("No user has configured their AP > 0\n"); verbose(" no user has configured their AP > 0\n");
} }
// Mark this job as inactive // Mark this job as inactive

View File

@ -22,35 +22,51 @@ limitations under the License.
// Include all settings and classes // Include all settings and classes
require_once('shared.inc.php'); require_once('shared.inc.php');
verbose("Running system notifications\n");
verbose(" IDLE Worker Notifications ...");
// Find all IDLE workers // Find all IDLE workers
$aWorkers = $worker->getAllIdleWorkers(); $aWorkers = $worker->getAllIdleWorkers();
if (empty($aWorkers)) { if (empty($aWorkers)) {
verbose("No idle workers found\n"); verbose(" no idle workers found\n");
} else { } else {
verbose(" found " . count($aWorkers) . " IDLE workers\n");
foreach ($aWorkers as $aWorker) { foreach ($aWorkers as $aWorker) {
$aData = $aWorker; $aData = $aWorker;
$aData['username'] = $user->getUserName($aWorker['account_id']); $aData['username'] = $user->getUserName($aWorker['account_id']);
$aData['subject'] = 'IDLE Worker : ' . $aWorker['username']; $aData['subject'] = 'IDLE Worker : ' . $aWorker['username'];
$aData['worker'] = $aWorker['username']; $aData['worker'] = $aWorker['username'];
$aData['email'] = $user->getUserEmail($aData['username']); $aData['email'] = $user->getUserEmail($aData['username']);
if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData)) verbose(" " . $aWorker['username'] . "...");
verbose($notification->getError() . "\n"); if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData)) {
} verbose(" " . $notification->getError() . "\n");
} } else {
verbose(" sent\n");
// We notified, lets check which recovered
$aNotifications = $notification->getAllActive('idle_worker');
if (!empty($aNotifications)) {
foreach ($aNotifications as $aNotification) {
$aData = json_decode($aNotification['data'], true);
$aWorker = $worker->getWorker($aData['id']);
if ($aWorker['active'] == 1) {
if ($notification->setInactive($aNotification['id'])) {
verbose("Marked notification " . $aNotification['id'] . " as inactive\n");
} else {
verbose("Failed to set notification inactive for " . $aWorker['username'] . "\n");
}
} }
} }
} }
verbose(" Reset IDLE Worker Notifications ...");
// We notified, lets check which recovered
$aNotifications = $notification->getAllActive('idle_worker');
if (!empty($aNotifications)) {
verbose(" found " . count($aNotifications) . " active notification(s)\n");
foreach ($aNotifications as $aNotification) {
$aData = json_decode($aNotification['data'], true);
$aWorker = $worker->getWorker($aData['id']);
verbose(" " . $aWorker['username'] . " ...");
if ($aWorker['active'] == 1) {
if ($notification->setInactive($aNotification['id'])) {
verbose(" updated #" . $aNotification['id'] . " for " . $aWorker['username'] . " as inactive\n");
} else {
verbose(" failed to update #" . $aNotification['id'] . " for " . $aWorker['username'] . "\n");
}
} else {
verbose(" still inactive\n");
}
}
} else {
verbose(" no active IDLE worker notifications\n");
}
?> ?>

View File

@ -25,25 +25,37 @@ require_once('shared.inc.php');
// Fetch all cachable values but disable fetching from cache // Fetch all cachable values but disable fetching from cache
$statistics->setGetCache(false); $statistics->setGetCache(false);
// Verbose output
verbose("Running statistical cache updates\n");
// Since fetching from cache is disabled, overwrite our stats // Since fetching from cache is disabled, overwrite our stats
verbose(" getRoundShares ...");
if (!$statistics->getRoundShares()) if (!$statistics->getRoundShares())
verbose("Unable to fetch and store current round shares\n"); verbose(" update failed");
verbose("\n getTopContributors shares ...");
if (!$statistics->getTopContributors('shares')) if (!$statistics->getTopContributors('shares'))
verbose("Unable to fetch and store top share contributors\n"); verbose(" update failed");
verbose("\n getTopContributors hashes ...");
if (!$statistics->getTopContributors('hashes')) if (!$statistics->getTopContributors('hashes'))
verbose("Unable to fetch and store top hashrate contributors\n"); verbose(" update failed");
verbose("\n getCurrentHashrate ...");
if (!$statistics->getCurrentHashrate()) if (!$statistics->getCurrentHashrate())
verbose("Unable to fetch and store pool hashrate\n"); verbose(" update failed");
// Admin specific statistics, we cache the global query due to slowness // Admin specific statistics, we cache the global query due to slowness
verbose("\n getAllUserStats ...");
if (!$statistics->getAllUserStats('%')) if (!$statistics->getAllUserStats('%'))
verbose("Unable to fetch and store admin panel full user list\n"); verbose(" update failed");
verbose("\n");
// Per user share statistics based on all shares submitted // Per user share statistics based on all shares submitted
verbose(" getUserShares ...\n");
$stmt = $mysqli->prepare("SELECT DISTINCT SUBSTRING_INDEX( `username` , '.', 1 ) AS username FROM " . $share->getTableName()); $stmt = $mysqli->prepare("SELECT DISTINCT SUBSTRING_INDEX( `username` , '.', 1 ) AS username FROM " . $share->getTableName());
if ($stmt && $stmt->execute() && $result = $stmt->get_result()) { if ($stmt && $stmt->execute() && $result = $stmt->get_result()) {
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
verbose(" " . $row['username'] . " ...");
if (!$statistics->getUserShares($user->getUserId($row['username']))) if (!$statistics->getUserShares($user->getUserId($row['username'])))
verbose("Failed to fetch and store user stats for " . $row['username'] . "\n"); verbose(" update failed");
verbose("\n");
} }
} }
?> ?>

View File

@ -25,7 +25,7 @@ require_once('shared.inc.php');
// Include additional file not set in autoloader // Include additional file not set in autoloader
require_once(CLASS_DIR . '/tools.class.php'); require_once(CLASS_DIR . '/tools.class.php');
verbose("Running updates\n"); verbose("Running scheduled updates\n");
verbose(" Price API Call ... "); verbose(" Price API Call ... ");
if ($price = $tools->getPrice()) { if ($price = $tools->getPrice()) {
verbose("found $price as price\n"); verbose("found $price as price\n");

View File

@ -173,8 +173,10 @@ class Notification extends Mail {
// Check if this user wants strType notifications // Check if this user wants strType notifications
$stmt = $this->mysqli->prepare("SELECT account_id FROM $this->tableSettings WHERE type = ? AND active = 1 AND account_id = ?"); $stmt = $this->mysqli->prepare("SELECT account_id FROM $this->tableSettings WHERE type = ? AND active = 1 AND account_id = ?");
if ($stmt && $stmt->bind_param('si', $strType, $account_id) && $stmt->execute() && $stmt->bind_result($id) && $stmt->fetch()) { if ($stmt && $stmt->bind_param('si', $strType, $account_id) && $stmt->execute() && $stmt->bind_result($id) && $stmt->fetch()) {
if ($stmt->close() && $this->sendMail('notifications/' . $strType, $aMailData) && $this->addNotification($account_id, $strType, $aMailData)) if ($stmt->close() && $this->sendMail('notifications/' . $strType, $aMailData) && $this->addNotification($account_id, $strType, $aMailData)) {
$this->setErrorMessage('Error sending mail notification');
return true; return true;
}
} else { } else {
$this->setErrorMessage('User disabled ' . $strType . ' notifications'); $this->setErrorMessage('User disabled ' . $strType . ' notifications');
} }