Skip to content

Commit 32ebfd8

Browse files
committed
Merge pull request #1922 from MPOS/disable-worker-notifications
[ADDED] IDLE Worker Global Switch
2 parents 0f13bd7 + 9941c61 commit 32ebfd8

File tree

8 files changed

+52
-38
lines changed

8 files changed

+52
-38
lines changed

cronjobs/notifications.php

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,49 @@
2929
$monitoring->endCronjob($cron_name, 'E0009', 0, true, false);
3030
}
3131

32-
$log->logDebug(" IDLE Worker Notifications ...");
33-
// Find all IDLE workers
34-
$aWorkers = $worker->getAllIdleWorkers();
35-
if (empty($aWorkers)) {
36-
$log->logDebug(" no idle workers found");
37-
} else {
38-
$log->logInfo(" found " . count($aWorkers) . " IDLE workers");
39-
foreach ($aWorkers as $aWorker) {
40-
$aData = $aWorker;
41-
$aData['username'] = $user->getUserName($aWorker['account_id']);
42-
$aData['subject'] = 'IDLE Worker : ' . $aWorker['username'];
43-
$aData['worker'] = $aWorker['username'];
44-
$aData['email'] = $user->getUserEmail($aData['username']);
45-
$log->logDebug(" " . $aWorker['username'] . "...");
46-
if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData))
47-
$log->logDebug(" Failed sending notifications: " . $notification->getCronError());
32+
if ($setting->getValue('notifications_disable_idle_worker') != 1) {
33+
$log->logDebug(" IDLE Worker Notifications ...");
34+
// Find all IDLE workers
35+
$aWorkers = $worker->getAllIdleWorkers();
36+
if (empty($aWorkers)) {
37+
$log->logDebug(" no idle workers found");
38+
} else {
39+
$log->logInfo(" found " . count($aWorkers) . " IDLE workers");
40+
foreach ($aWorkers as $aWorker) {
41+
$aData = $aWorker;
42+
$aData['username'] = $user->getUserName($aWorker['account_id']);
43+
$aData['subject'] = 'IDLE Worker : ' . $aWorker['username'];
44+
$aData['worker'] = $aWorker['username'];
45+
$aData['email'] = $user->getUserEmail($aData['username']);
46+
$log->logDebug(" " . $aWorker['username'] . "...");
47+
if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData))
48+
$log->logDebug(" Failed sending notifications: " . $notification->getCronError());
49+
}
4850
}
49-
}
5051

5152

52-
$log->logDebug(" Reset IDLE Worker Notifications ...");
53-
// We notified, lets check which recovered
54-
$aNotifications = $notification->getAllActive('idle_worker');
55-
if (!empty($aNotifications)) {
56-
$log->logInfo(" found " . count($aNotifications) . " active notification(s)");
57-
foreach ($aNotifications as $aNotification) {
58-
$aData = json_decode($aNotification['data'], true);
59-
$aWorker = $worker->getWorker($aData['id']);
60-
$log->logDebug(" " . $aWorker['username'] . " ...");
61-
if ($aWorker['hashrate'] > 0) {
62-
if ($notification->setInactive($aNotification['id'])) {
63-
$log->logDebug(" updated #" . $aNotification['id'] . " for " . $aWorker['username'] . " as inactive");
53+
$log->logDebug(" Reset IDLE Worker Notifications ...");
54+
// We notified, lets check which recovered
55+
$aNotifications = $notification->getAllActive('idle_worker');
56+
if (!empty($aNotifications)) {
57+
$log->logInfo(" found " . count($aNotifications) . " active notification(s)");
58+
foreach ($aNotifications as $aNotification) {
59+
$aData = json_decode($aNotification['data'], true);
60+
$aWorker = $worker->getWorker($aData['id']);
61+
$log->logDebug(" " . $aWorker['username'] . " ...");
62+
if ($aWorker['hashrate'] > 0) {
63+
if ($notification->setInactive($aNotification['id'])) {
64+
$log->logDebug(" updated #" . $aNotification['id'] . " for " . $aWorker['username'] . " as inactive");
65+
} else {
66+
$log->logError(" failed to update #" . $aNotification['id'] . " for " . $aWorker['username']);
67+
}
6468
} else {
65-
$log->logError(" failed to update #" . $aNotification['id'] . " for " . $aWorker['username']);
69+
$log->logDebug(" still inactive");
6670
}
67-
} else {
68-
$log->logDebug(" still inactive");
6971
}
72+
} else {
73+
$log->logDebug(" no active IDLE worker notifications");
7074
}
71-
} else {
72-
$log->logDebug(" no active IDLE worker notifications");
7375
}
7476

7577
require_once('cron_end.inc.php');

public/include/config/admin_settings.inc.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,10 @@
425425
'name' => 'notifications_disable_block', 'value' => $setting->getValue('notifications_disable_block'),
426426
'tooltip' => 'Enable/Disable block notifications globally. Will remove the user option too.'
427427
);
428+
$aSettings['notifications'][] = array(
429+
'display' => 'Disable IDLE Worker Notifications', 'type' => 'select',
430+
'options' => array( 0 => 'No', 1 => 'Yes'),
431+
'default' => 0,
432+
'name' => 'notifications_disable_idle_worker', 'value' => $setting->getValue('notifications_disable_idle_worker'),
433+
'tooltip' => 'Enable/Disable IDLE worker notifications globally. Will remove the user option too.'
434+
);

public/include/pages/account/notifications.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
// Fetch global settings
2626
$smarty->assign('DISABLE_BLOCKNOTIFICATIONS', $setting->getValue('notifications_disable_block'));
27+
$smarty->assign('DISABLE_IDLEWORKERNOTIFICATIONS', $setting->getValue('notifications_disable_idle_worker'));
2728

2829
// Fetch user notification settings
2930
$aSettings = $notification->getNotificationSettings($_SESSION['USERDATA']['id']);

public/include/pages/account/workers.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
break;
4141
}
4242

43+
$smarty->assign('DISABLE_IDLEWORKERNOTIFICATIONS', $setting->getValue('notifications_disable_idle_worker'));
4344
$aWorkers = $worker->getWorkers($_SESSION['USERDATA']['id']);
4445
if (!$aWorkers) $_SESSION['POPUP'][] = array('CONTENT' => 'You have no workers configured', 'TYPE' => 'errormsg');
4546

public/include/pages/admin/poolworkers.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
$aWorkers = $worker->getAllWorkers($iLimit, $interval, $start);
1717

18+
$smarty->assign('DISABLE_IDLEWORKERNOTIFICATIONS', $setting->getValue('notifications_disable_idle_worker'));
1819
$smarty->assign('LIMIT', $iLimit);
1920
$smarty->assign('WORKERS', $aWorkers);
2021
$smarty->assign('CONTENT', 'default.tpl');

public/templates/mpos/account/notifications/default.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<th align="left">Type</th>
1414
<th align="center">Active</th>
1515
</tr>
16+
{if $DISABLE_IDLEWORKERNOTIFICATIONS|default:"" != 1}
1617
<tr>
1718
<td align="left">IDLE Worker</td>
1819
<td>
@@ -25,6 +26,7 @@
2526
</span>
2627
</td>
2728
</tr>
29+
{/if}
2830
{if $DISABLE_BLOCKNOTIFICATIONS|default:"" != 1}
2931
<tr>
3032
<td align="left">New Blocks</td>

public/templates/mpos/account/workers/default.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<th align="left">Worker Login</th>
3838
<th align="left">Worker Password</th>
3939
<th align="center">Active</th>
40-
{if $GLOBAL.config.disable_notifications != 1}<th align="center">Monitor</th>{/if}
40+
{if $GLOBAL.config.disable_notifications != 1 && $DISABLE_IDLEWORKERNOTIFICATIONS != 1}<th align="center">Monitor</th>{/if}
4141
<th align="right">Khash/s</th>
4242
<th align="right">Difficulty</th>
4343
<th align="center" style="padding-right: 25px;">Action</th>
@@ -51,7 +51,7 @@
5151
<td align="left"{if $WORKERS[worker].hashrate > 0} style="color: orange"{/if}>{$username.0|escape}.<input name="data[{$WORKERS[worker].id}][username]" value="{$username.1|escape}" size="10" required/></td>
5252
<td align="left"><input type="text" name="data[{$WORKERS[worker].id}][password]" value="{$WORKERS[worker].password|escape}" size="10" required></td>
5353
<td align="center"><i class="icon-{if $WORKERS[worker].hashrate > 0}ok{else}cancel{/if}"></i></td>
54-
{if $GLOBAL.config.disable_notifications != 1}
54+
{if $GLOBAL.config.disable_notifications != 1 && $DISABLE_IDLEWORKERNOTIFICATIONS != 1}
5555
<td>
5656
<span class="toggle">
5757
<label for="data[{$WORKERS[worker].id}][monitor]">

public/templates/mpos/admin/poolworkers/default.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<th align="left">Worker Name</th>
2626
<th align="left">Password</th>
2727
<th align="center">Active</th>
28-
{if $GLOBAL.config.disable_notifications != 1}<th align="center">Monitor</th>{/if}
2928
<th align="right">Khash/s</th>
29+
{if $GLOBAL.config.disable_notifications != 1 && $DISABLE_IDLEWORKERNOTIFICATIONS != 1}<th align="center">Monitor</th>{/if}
3030
<th align="right">Difficulty</th>
3131
<th align="right" style="padding-right: 25px;">Avg Difficulty</th>
3232
</tr>
@@ -38,7 +38,7 @@
3838
<td align="left">{$WORKERS[worker].username|escape}</td>
3939
<td align="left">{$WORKERS[worker].password|escape}</td>
4040
<td align="center"><i class="icon-{if $WORKERS[worker].hashrate > 0}ok{else}cancel{/if}"></i></td>
41-
{if $GLOBAL.config.disable_notifications != 1}
41+
{if $GLOBAL.config.disable_notifications != 1 && $DISABLE_IDLEWORKERNOTIFICATIONS != 1}
4242
<td align="center"><i class="icon-{if $WORKERS[worker].monitor}ok{else}cancel{/if}"></i></td>
4343
{/if}
4444
<td align="right">{$WORKERS[worker].hashrate|number_format|default:"0"}</td>

0 commit comments

Comments
 (0)