Skip to content

Commit

Permalink
improve schedule seeder (#672)
Browse files Browse the repository at this point in the history
* improve schedule seeder

* styleci

* bump dependency version
  • Loading branch information
recursivetree authored Mar 28, 2024
1 parent 3ab32b5 commit 27a4a9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"erusev/parsedown": "^1.7",
"eveseat/eseye": "^3.0",
"eveseat/eveapi": "^5.0",
"eveseat/services": "^5.0.3",
"eveseat/services": "^5.0.6",
"guzzlehttp/guzzle": "^7.0",
"intervention/image": "^2.0",
"laravel/framework": "^10.0",
Expand Down
50 changes: 22 additions & 28 deletions src/database/seeders/ScheduleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,41 @@

namespace Seat\Web\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Seat\Services\Seeding\AbstractScheduleSeeder;

/**
* Class ScheduleSeeder.
*
* @package Seat\Web\database\seeds
*/
class ScheduleSeeder extends Seeder
class ScheduleSeeder extends AbstractScheduleSeeder
{
/**
* @var array
* Returns an array of schedules that should be seeded whenever the stack boots up.
*
* @return array
*/
protected $schedules = [
[ // Horizon Metrics | Every Five Minutes
'command' => 'horizon:snapshot',
'expression' => '*/5 * * * *',
'allow_overlap' => false,
'allow_maintenance' => false,
'ping_before' => null,
'ping_after' => null,
],
];
public function getSchedules(): array
{
return [
[ // Horizon Metrics | Every Five Minutes
'command' => 'horizon:snapshot',
'expression' => '*/5 * * * *',
'allow_overlap' => false,
'allow_maintenance' => false,
'ping_before' => null,
'ping_after' => null,
],
];
}

/**
* Run the database seeds.
* Returns a list of commands to remove from the schedule.
*
* @return void
* @return array
*/
public function run()
public function getDeprecatedSchedules(): array
{
// 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);
}
}
return [];
}
}

0 comments on commit 27a4a9e

Please sign in to comment.