Skip to content

Commit

Permalink
refactor: better organize jobs (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio authored Nov 30, 2024
1 parent 7d610fb commit 5e1b645
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function form(Form $form): Form
->mapWithKeys(fn (string $job) => [
$job => $job::name(),
]);
}),
})
->searchable()
->preload()
->required(),

Select::make('cron')
->label(__('app.field.cron'))
Expand All @@ -47,23 +50,18 @@ public function form(Form $form): Form

Fieldset::make('source')
->label('Source')
->columns(4)
->columns(2)
->schema([
TextInput::make('source_url')
->label(__('app.field.source_url'))
->columnSpan(3),

TextInput::make('source_part')
->label(__('app.field.source_part')),
->columnSpanFull(),

TextInput::make('source_username')
->label(__('app.field.source_username'))
->columnSpan(2),
->label(__('app.field.source_username')),

TextInput::make('source_password')
->label(__('app.field.source_password'))
->password()
->columnSpan(2),
->password(),
]),
]);
}
Expand All @@ -80,7 +78,7 @@ public function table(Table $table): Table
TextColumn::make('job')
->label(__('app.field.job'))
->description(fn (string $state) => $state, 'above')
->formatStateUsing(fn (string $state) => $state::name()),
->formatStateUsing(fn (string $state) => rescue(fn () => $state::name())),

TextColumn::make('cron')
->label(__('app.field.cron')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Europarl240609\Records;
namespace App\Jobs\Y2024\M06\EuropeanParliament\Records;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -17,7 +17,7 @@ class FetchRecordsJob extends SchedulableJob
{
public static function name(): string
{
return 'Europarlamentare 09.06.2024 / Procese Verbale';
return '2024-06-09 / Europarlamentare / Procese Verbale';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Europarl240609\Records;
namespace App\Jobs\Y2024\M06\EuropeanParliament\Records;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Europarl240609\Records;
namespace App\Jobs\Y2024\M06\EuropeanParliament\Records;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Europarl240609\Turnouts;
namespace App\Jobs\Y2024\M06\EuropeanParliament\Turnouts;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -19,7 +19,7 @@ class FetchTurnoutsJob extends SchedulableJob
{
public static function name(): string
{
return 'Europarlamentare 09.06.2024 / Prezență';
return '2024-06-09 / Europarlamentare / Prezență';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Europarl240609\Turnouts;
namespace App\Jobs\Y2024\M06\EuropeanParliament\Turnouts;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Europarl240609\Turnouts;
namespace App\Jobs\Y2024\M06\EuropeanParliament\Turnouts;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Presidential241124\Records;
namespace App\Jobs\Y2024\M11\President\Records;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -20,7 +20,7 @@ class FetchRecordsJob extends SchedulableJob
{
public static function name(): string
{
return 'Prezidențiale 24.11.2024 / Procese Verbale';
return '2024-11-24 / Prezidențiale / Procese Verbale';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Presidential241124\Records;
namespace App\Jobs\Y2024\M11\President\Records;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Presidential241124\Records;
namespace App\Jobs\Y2024\M11\President\Records;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Presidential241124\Records;
namespace App\Jobs\Y2024\M11\President\Records;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Parlamentare01122024\Turnouts;
namespace App\Jobs\Y2024\M11\President\Turnouts;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -19,7 +19,7 @@ class FetchTurnoutsJob extends SchedulableJob
{
public static function name(): string
{
return 'Parlamentar 01.12.2024 / Prezență';
return '2024-11-24 / Prezidențiale / Prezență';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Presidential241124\Turnouts;
namespace App\Jobs\Y2024\M11\President\Turnouts;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Presidential241124\Turnouts;
namespace App\Jobs\Y2024\M11\President\Turnouts;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\ReferendumBucuresti241124\Records;
namespace App\Jobs\Y2024\M11\ReferendumBucuresti\Records;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -20,7 +20,7 @@ class FetchRecordsJob extends SchedulableJob
{
public static function name(): string
{
return 'Referendum Bucuresti 24.11.2024 / Procese Verbale';
return '2024-11-24 / Referendum București / Procese Verbale';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\ReferendumBucuresti241124\Records;
namespace App\Jobs\Y2024\M11\ReferendumBucuresti\Records;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\ReferendumBucuresti241124\Turnouts;
namespace App\Jobs\Y2024\M11\ReferendumBucuresti\Turnouts;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -19,7 +19,7 @@ class FetchTurnoutsJob extends SchedulableJob
{
public static function name(): string
{
return 'Referendum Bucuresti 24.11.2024 / Prezență';
return '2024-11-24 / Referendum București / Prezență';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\ReferendumBucuresti241124\Turnouts;
namespace App\Jobs\Y2024\M11\ReferendumBucuresti\Turnouts;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Parlamentare01122024\Records;
namespace App\Jobs\Y2024\M12\Parliament\Records;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -20,7 +20,7 @@ class FetchRecordsJob extends SchedulableJob
{
public static function name(): string
{
return 'Parlamentar 01.12.2024 / Procese Verbale';
return '2024-12-01 / Parlamentare / Procese Verbale';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Parlamentare01122024\Records;
namespace App\Jobs\Y2024\M12\Parliament\Records;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Parlamentare01122024\Records;
namespace App\Jobs\Y2024\M12\Parliament\Records;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand All @@ -20,7 +20,7 @@ class ImportCorrespondenceRecordsJob extends SchedulableJob

public static function name(): string
{
return 'Parlamentare 06.12.2020/ Procese Verbale Corespondență';
return '2024-12-01 / Parlamentare / Procese Verbale Corespondență';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Parlamentare01122024\Records;
namespace App\Jobs\Y2024\M12\Parliament\Records;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Presidential241124\Turnouts;
namespace App\Jobs\Y2024\M12\Parliament\Turnouts;

use App\Jobs\DeleteTemporaryTableData;
use App\Jobs\PersistTemporaryTableData;
Expand All @@ -19,7 +19,7 @@ class FetchTurnoutsJob extends SchedulableJob
{
public static function name(): string
{
return 'Prezidențiale 24.11.2024 / Prezență';
return '2024-12-01 / Parlamentare / Prezență';
}

public function execute(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Parlamentare01122024\Turnouts;
namespace App\Jobs\Y2024\M12\Parliament\Turnouts;

use App\Events\CountryCodeNotFound;
use App\Exceptions\CountryCodeNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Jobs\Parlamentare01122024\Turnouts;
namespace App\Jobs\Y2024\M12\Parliament\Turnouts;

use App\Exceptions\MissingSourceFileException;
use App\Models\County;
Expand Down
5 changes: 0 additions & 5 deletions app/Models/ScheduledJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ScheduledJob extends Model
'job',
'cron',
'is_enabled',
'source_part',
'source_url',
'source_username',
'source_password',
Expand Down Expand Up @@ -86,10 +85,6 @@ public function getPreparedSourceUrl(array $map = []): string
throw new MissingSourceUrlException;
}

$map = array_merge($map, [
'{{part}}' => $this->source_part,
]);

$search = array_keys($map);
$replace = array_values($map);

Expand Down
6 changes: 3 additions & 3 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ protected function resolveSchedule(): void
ScheduledJob::query()
->with('election')
->where('is_enabled', true)
->each(
fn (ScheduledJob $job) => $schedule
->each(fn (ScheduledJob $job) => rescue(
fn () => $schedule
->job(new $job->job($job))
->cron($job->cron->value)
->withoutOverlapping()
->onOneServer()
);
));
} catch (QueryException|MissingAppKeyException $th) {
// fix for composer install
}
Expand Down
Loading

0 comments on commit 5e1b645

Please sign in to comment.