-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CronJob] New CronJob package (#246)
--------- Co-authored-by: Martin Poirier Théorêt <[email protected]>
- Loading branch information
1 parent
d260f93
commit 8e7236c
Showing
47 changed files
with
2,456 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ jobs: | |
- aws-tool-kit | ||
- console | ||
- core | ||
- cron-job | ||
- doctrine-extra | ||
- entity-migrator | ||
- fixer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240416163152 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE cron_job__cron_job ( | ||
id INT AUTO_INCREMENT NOT NULL, | ||
name VARCHAR(255) NOT NULL, | ||
active TINYINT(1) DEFAULT 0 NOT NULL, | ||
command LONGTEXT NOT NULL, | ||
schedule VARCHAR(255) DEFAULT NULL, | ||
time_to_live INT DEFAULT 0 NOT NULL, | ||
priority INT DEFAULT NULL, | ||
UNIQUE INDEX UNIQ_5D454BF65E237E06 (name), | ||
PRIMARY KEY(id) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('CREATE TABLE cron_job__cron_job_execution ( | ||
id INT AUTO_INCREMENT NOT NULL, | ||
cron_job_id INT NOT NULL, | ||
requested_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
`force` TINYINT(1) DEFAULT 0 NOT NULL, | ||
execution_started_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
execution_ended_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
execution_delay INT DEFAULT NULL, | ||
exit_code INT DEFAULT NULL, | ||
error JSON DEFAULT NULL, | ||
INDEX IDX_2DD653DD79099ED8 (cron_job_id), | ||
PRIMARY KEY(id) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE | ||
cron_job__cron_job_execution | ||
ADD | ||
CONSTRAINT FK_2DD653DD79099ED8 FOREIGN KEY (cron_job_id) REFERENCES cron_job__cron_job (id) ON DELETE CASCADE'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE cron_job__cron_job_execution DROP FOREIGN KEY FK_2DD653DD79099ED8'); | ||
$this->addSql('DROP TABLE cron_job__cron_job'); | ||
$this->addSql('DROP TABLE cron_job__cron_job_execution'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/vendor/ | ||
/.idea/ | ||
composer.lock | ||
|
||
###> phpunit/phpunit ### | ||
/phpunit.xml | ||
.phpunit.result.cache | ||
###< phpunit/phpunit ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Component\CronJob\Command; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Draw\Component\CronJob\CronJobProcessor; | ||
use Draw\Component\CronJob\Entity\CronJob; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
#[AsCommand(name: 'draw:cron-job:queue-by-name')] | ||
class QueueCronJobByNameCommand extends Command | ||
{ | ||
public function __construct( | ||
private ManagerRegistry $managerRegistry, | ||
private CronJobProcessor $cronJobProcessor, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Queues cron job by name') | ||
->addArgument('name', InputArgument::REQUIRED, 'Cron job name'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$cronJob = $this->managerRegistry | ||
->getRepository(CronJob::class) | ||
->findOneBy(['name' => $input->getArgument('name')]); | ||
|
||
if (null === $cronJob) { | ||
$io->error('Cron job could not be found.'); | ||
|
||
return Command::FAILURE; | ||
} | ||
|
||
$io->section('Queueing cron job...'); | ||
|
||
$this->cronJobProcessor->queue($cronJob, true); | ||
|
||
$io->section('Cron job successfully queued.'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
Oops, something went wrong.