Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: schedule cache blocks command #1159

Merged
merged 7 commits into from
Jan 27, 2025
5 changes: 5 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Console\Commands\BuildForgingStats;
use App\Console\Commands\CacheAddressStatistics;
use App\Console\Commands\CacheAnnualStatistics;
use App\Console\Commands\CacheBlocks;
use App\Console\Commands\CacheContractAddresses;
use App\Console\Commands\CacheCurrenciesData;
use App\Console\Commands\CacheFees;
Expand Down Expand Up @@ -109,6 +110,10 @@ protected function schedule(Schedule $schedule)
if (config('arkscan.scout.run_jobs', false) === true) {
$schedule->command(ScoutIndexModels::class)->everyMinute();
}

if (config('broadcasting.default') !== 'reverb') {
$schedule->command(CacheBlocks::class)->everyFiveMinutes();
}
}

/**
Expand Down
33 changes: 32 additions & 1 deletion tests/Feature/Console/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Config;

const EVERY_MINUTE = '* * * * *';
const EVERY_MINUTE = '* * * * *';
const EVERY_FIVE_MINUTE = '*/5 * * * *';

it('schedules the `scout:index-models` command correctly if enabled', function () {
Config::set('arkscan.scout.run_jobs', true);
Expand Down Expand Up @@ -37,3 +38,33 @@

expect($events->count())->toBe(0);
});

it('schedules the `explorer:cache-blocks` command if using reverb', function () {
Config::set('broadcasting.default', 'reverb');

$schedule = app()->make(Schedule::class);

$events = collect($schedule->events())->filter(function (Event $event) {
return stripos($event->command, 'explorer:cache-blocks');
});

expect($events->count())->toBe(0);
});

it('does not schedule the `explorer:cache-blocks` command if disabled', function () {
Config::set('broadcasting.default', null);

$schedule = app()->make(Schedule::class);

$events = collect($schedule->events())->filter(function (Event $event) {
return stripos($event->command, 'explorer:cache-blocks');
});

if ($events->count() === 0) {
$this->fail('No events found');
}

$events->each(function (Event $event) {
$this->assertEquals(EVERY_FIVE_MINUTE, $event->expression);
});
});
Loading