Skip to content

Commit c6b8e4c

Browse files
Jellyfrogmurrant
andauthored
Move notification fetching from daily to a scheduled job (librenms#18247)
* Implement random scheduling times per host to prevents thundering herd problems The randomization is stable per host, meaning it will always return the same "random" value per input. This is needed so the scheduler doesn't run the same job multiple times * Move notification fetching from daily to a scheduled job * Apply fixes from StyleCI * Apply fixes from StyleCI --------- Co-authored-by: Tony Murray <[email protected]>
1 parent 3283ae2 commit c6b8e4c

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Console\LnmsCommand;
6+
use Illuminate\Support\Facades\Cache;
7+
use LibreNMS\Util\Notifications;
8+
9+
class MaintenanceFetchRSS extends LnmsCommand
10+
{
11+
/**
12+
* The name of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $name = 'maintenance:fetch-rss';
17+
18+
/**
19+
* Execute the console command.
20+
*/
21+
public function handle(): int
22+
{
23+
$lock = Cache::lock('notifications', 86000);
24+
if ($lock->get()) {
25+
Notifications::post();
26+
$lock->release();
27+
28+
return 0;
29+
}
30+
31+
return 1;
32+
}
33+
}

daily.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,6 @@
188188
}
189189
}
190190

191-
if ($options['f'] === 'notifications') {
192-
$lock = Cache::lock('notifications', 86000);
193-
if ($lock->get()) {
194-
Notifications::post();
195-
$lock->release();
196-
}
197-
}
198-
199191
if ($options['f'] === 'bill_data') {
200192
// Deletes data older than XX months before the start of the last complete billing period
201193
$msg = "Deleting billing data more than %d month before the last completed billing cycle\n";

daily.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ main () {
369369

370370
# List all tasks to do after pull in the order of execution
371371
status_run 'Updating SQL-Schema' './lnms migrate --force --no-interaction --isolated'
372-
status_run 'Updating submodules' "$DAILY_SCRIPT submodules"
373372
status_run 'Cleaning up DB' "$DAILY_SCRIPT cleanup"
374-
status_run 'Fetching notifications' "$DAILY_SCRIPT notifications"
375373
status_run 'Caching PeeringDB data' "$DAILY_SCRIPT peeringdb"
376374
;;
377375
cleanup)
@@ -392,16 +390,6 @@ main () {
392390
"ports_purge")
393391
call_daily_php "${options[@]}"
394392
;;
395-
submodules)
396-
# Init+Update our submodules
397-
git submodule --quiet init
398-
git submodule --quiet update
399-
;;
400-
notifications)
401-
# Get notifications
402-
options=("notifications")
403-
call_daily_php "${options[@]}"
404-
;;
405393
peeringdb)
406394
options=("peeringdb")
407395
call_daily_php "${options[@]}"

routes/console.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use App\Console\Commands\MaintenanceCleanupNetworks;
44
use App\Console\Commands\MaintenanceCleanupSyslog;
55
use App\Console\Commands\MaintenanceFetchOuis;
6+
use App\Console\Commands\MaintenanceFetchRSS;
67
use App\Jobs\PingCheck;
78
use Illuminate\Support\Facades\Artisan;
89
use Illuminate\Support\Facades\Cache;
@@ -184,6 +185,11 @@
184185
->onOneServer()
185186
->appendOutputTo($maintenance_log_file);
186187

188+
Schedule::command(MaintenanceFetchRSS::class)
189+
->dailyAt(Time::pseudoRandomBetween('03:00', '03:59'))
190+
->onOneServer()
191+
->appendOutputTo($maintenance_log_file);
192+
187193
Schedule::command(MaintenanceCleanupSyslog::class)
188194
->dailyAt('03:30')
189195
->onOneServer()

0 commit comments

Comments
 (0)