job-runner / symfony-console-adapter
1.3.0
2024-05-08 09:13 UTC
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- job-runner/job-runner: ^1.3
- symfony/console: ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- phpunit/phpunit: ^10.5.20
- psalm/plugin-phpunit: ^0.19.0
- vimeo/psalm: ^5.23
This package is auto-updated.
Last update: 2024-09-19 23:48:52 UTC
README
此包为JobRunner提供symfony/console适配器。
安装
composer require job-runner/symfony-console-adapter
使用
<?php declare(strict_types=1); use JobRunner\JobRunner\Job\CliJob; use JobRunner\JobRunner\Job\JobList; use JobRunner\JobRunner\CronJobRunner; use JobRunner\JobRunner\SymfonyConsole\SymfonyConsoleEventListener; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\SingleCommandApplication; require 'vendor/autoload.php'; (new SingleCommandApplication()) ->setName('My Super Command') // Optional ->setVersion('1.0.0') // Optional ->addOption('bar', null, InputOption::VALUE_REQUIRED) ->setCode(function (InputInterface $input, OutputInterface $output) { $jobCollection = new JobList(); $jobCollection->push(new CliJob('php ' . __DIR__ . '/tutu.php', '* * * * *')); $jobCollection->push(new CliJob('php ' . __DIR__ . '/titi.php', '* * * * *', 'sample')); $jobCollection->push(new CliJob('php ' . __DIR__ . '/titi.php', '1 1 1 1 1', 'hehe')); $jobCollection->push(new CliJob('php ' . __DIR__ . '/arg.php', '* * * * *')); $section = $output->section(); CronJobRunner::create() ->withEventListener(new SymfonyConsoleEventListener($section, new Table($section))) ->run($jobCollection); }) ->run();