From 7159641456c1a40a0ba9e209b53d4cac617c14b4 Mon Sep 17 00:00:00 2001 From: recursive_tree Date: Sun, 24 Mar 2024 11:32:50 +0100 Subject: [PATCH 1/3] improve schedule seeding --- src/database/seeders/ScheduleSeeder.php | 299 +++++++++++------------- 1 file changed, 142 insertions(+), 157 deletions(-) diff --git a/src/database/seeders/ScheduleSeeder.php b/src/database/seeders/ScheduleSeeder.php index ec2084e5..b8298bd5 100644 --- a/src/database/seeders/ScheduleSeeder.php +++ b/src/database/seeders/ScheduleSeeder.php @@ -22,173 +22,141 @@ namespace Seat\Eveapi\Database\Seeders; -use Illuminate\Database\Seeder; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\DB; +use Seat\Services\Seeding\AbstractScheduleSeeder; /** * Class ScheduleSeeder. * * @package Seat\Eveapi\database\seeds */ -class ScheduleSeeder extends Seeder +class ScheduleSeeder extends AbstractScheduleSeeder { - /** - * @var array - */ - protected $schedules = [ - [ // ESI Status | Every Minute - 'command' => 'esi:update:status', - 'expression' => '* * * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // EVE Server Status | Every Minute - 'command' => 'eve:update:status', - 'expression' => '* * * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // SDE Data | Monthly - 'command' => 'eve:update:sde', - 'expression' => '0 0 1 * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Update a set of tokens | Every 2 Minutes - 'command' => 'seat:buckets:update', - 'expression' => '*/2 * * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Public Data | Daily at 12am - 'command' => 'esi:update:public', - 'expression' => '0 0 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Character Affiliation | Every two hours - 'command' => 'esi:update:affiliations', - 'expression' => '0 */2 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Character Notifications | Every twenty minutes - 'command' => 'esi:update:notifications', - 'expression' => '*/20 * * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Killmails | Every fifteen minutes - 'command' => 'esi:update:killmails', - 'expression' => '*/15 * * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Contracts | Every fifteen minutes - 'command' => 'esi:update:contracts', - 'expression' => '*/15 * * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Prices | Once a day - 'command' => 'esi:update:prices', - 'expression' => '0 13 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Alliances | Once a day - 'command' => 'esi:update:alliances', - 'expression' => '0 14 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Insurances Data | Once a day - 'command' => 'esi:update:insurances', - 'expression' => '0 7 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Sovereignty Data | Once a day - 'command' => 'esi:update:sovereignty', - 'expression' => '0 19 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Stations Data | Once a day - 'command' => 'esi:update:stations', - 'expression' => '0 1 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - [ // Horizon remove batches older than 48 hours | Once a day - 'command' => 'queue:prune-batches --hours=48', - 'expression' => '0 3 * * *', - 'allow_overlap' => false, - 'allow_maintenance' => false, - 'ping_before' => null, - 'ping_after' => null, - ], - ]; /** - * Run the database seeds. + * Returns an array of schedules that should be seeded whenever the stack boots up * - * @return void + * @return array */ - public function run() + function getSchedules(): array { - // add randomness to default schedules - $this->seedRandomize(); - - // drop deprecated commands - DB::table('schedules')->whereIn('command', [ - 'alerts:run', - 'esi:update:serverstatus', - 'esi:update:esistatus', - 'esi:update:characters', - 'esi:update:corporations', - ])->delete(); + $schedules = [ + [ // ESI Status | Every Minute + 'command' => 'esi:update:status', + 'expression' => '* * * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // SDE Data | Monthly + 'command' => 'eve:update:sde', + 'expression' => '0 0 1 * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Update a set of tokens | Every 2 Minutes + 'command' => 'seat:buckets:update', + 'expression' => '*/2 * * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Public Data | Daily at 12am + 'command' => 'esi:update:public', + 'expression' => '0 0 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Character Affiliation | Every two hours + 'command' => 'esi:update:affiliations', + 'expression' => '0 */2 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Character Notifications | Every twenty minutes + 'command' => 'esi:update:notifications', + 'expression' => '*/20 * * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Killmails | Every fifteen minutes + 'command' => 'esi:update:killmails', + 'expression' => '*/15 * * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Contracts | Every fifteen minutes + 'command' => 'esi:update:contracts', + 'expression' => '*/15 * * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Prices | Once a day + 'command' => 'esi:update:prices', + 'expression' => '0 13 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Alliances | Once a day + 'command' => 'esi:update:alliances', + 'expression' => '0 14 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Insurances Data | Once a day + 'command' => 'esi:update:insurances', + 'expression' => '0 7 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Sovereignty Data | Once a day + 'command' => 'esi:update:sovereignty', + 'expression' => '0 19 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Stations Data | Once a day + 'command' => 'esi:update:stations', + 'expression' => '0 1 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + [ // Horizon remove batches older than 48 hours | Once a day + 'command' => 'queue:prune-batches --hours=48', + 'expression' => '0 3 * * *', + 'allow_overlap' => false, + 'allow_maintenance' => false, + 'ping_before' => null, + 'ping_after' => null, + ], + ]; - // Check if we have the schedules, else, - // insert them - foreach ($this->schedules as $job) { - if (DB::table('schedules')->where('command', $job['command'])->exists()) { - DB::table('schedules')->where('command', $job['command'])->update([ - 'expression' => $job['expression'], - ]); - } else { - DB::table('schedules')->insert($job); - } - } + // spread out ESI load + return $this->seedRandomize($schedules); } /** @@ -197,16 +165,16 @@ public function run() * * @see https://github.com/eveseat/seat/issues/731 */ - private function seedRandomize() + private function seedRandomize($schedules): array { // except utc 11 and utc 12 $hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; - foreach ($this->schedules as $key => $schedule) { + foreach ($schedules as $key => $schedule) { switch ($schedule['command']) { // use random minute - every 2 hours case 'esi:update:affiliations': - $this->schedules[$key]['expression'] = sprintf('%d */2 * * *', rand(0, 59)); + $schedules[$key]['expression'] = sprintf('%d */2 * * *', rand(0, 59)); break; // use random minute and hour, once a day case 'esi:update:public': @@ -215,9 +183,26 @@ private function seedRandomize() case 'esi:update:insurances': case 'esi:update:sovereignty': case 'esi:update:stations': - $this->schedules[$key]['expression'] = sprintf('%d %d * * *', rand(0, 59), Arr::random($hours)); + $schedules[$key]['expression'] = sprintf('%d %d * * *', rand(0, 59), Arr::random($hours)); break; } } + return $schedules; + } + + /** + * Returns a list of commands to remove from the schedule + * @return array + */ + function getDeprecatedSchedules(): array + { + // these commands are no longer in use, remove them + return [ + 'alerts:run', + 'esi:update:serverstatus', + 'esi:update:esistatus', + 'esi:update:characters', + 'esi:update:corporations', + ]; } } From def5149d7e1947ea10f45198c109a68e7bae4c6c Mon Sep 17 00:00:00 2001 From: recursive_tree Date: Sun, 24 Mar 2024 11:34:24 +0100 Subject: [PATCH 2/3] styleci --- src/database/seeders/ScheduleSeeder.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/database/seeders/ScheduleSeeder.php b/src/database/seeders/ScheduleSeeder.php index b8298bd5..592951bf 100644 --- a/src/database/seeders/ScheduleSeeder.php +++ b/src/database/seeders/ScheduleSeeder.php @@ -32,13 +32,12 @@ */ class ScheduleSeeder extends AbstractScheduleSeeder { - /** - * Returns an array of schedules that should be seeded whenever the stack boots up + * Returns an array of schedules that should be seeded whenever the stack boots up. * * @return array */ - function getSchedules(): array + public function getSchedules(): array { $schedules = [ [ // ESI Status | Every Minute @@ -187,14 +186,16 @@ private function seedRandomize($schedules): array break; } } + return $schedules; } /** - * Returns a list of commands to remove from the schedule + * Returns a list of commands to remove from the schedule. + * * @return array */ - function getDeprecatedSchedules(): array + public function getDeprecatedSchedules(): array { // these commands are no longer in use, remove them return [ From 2c72e5c8c155f69c1ec6e1128eeada2589742312 Mon Sep 17 00:00:00 2001 From: recursive_tree Date: Wed, 27 Mar 2024 16:39:23 +0100 Subject: [PATCH 3/3] bump dependency version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 56b3dc09..05381ddf 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "laravel/framework": "^10.0", "maatwebsite/excel": "^3.1.45", "eveseat/eseye": "^3.0", - "eveseat/services": "^5.0.1", + "eveseat/services": "^5.0.6", "guzzlehttp/guzzle": "^7.0", "doctrine/dbal": "^3.0", "psr/simple-cache": "^3.0",