Emdrive, (*1)
This bundle provides a built-in service that runs indefinitely and allows to trigger execution of Symfony\Component\Console\Command\Command on daily or interval bases, (*2)
Installation, (*3)
Open a command console, enter your project directory and execute the following command to download the latest version of this bundle:, (*4)
composer require maksslesarenko/emdrive
, (*5)
Configuration, (*6)
emdrive:
server_name: main # incase app is running on multiple servers this has to be unique
pool_size: 5 # number of simultanious commands allowed to be execute
tick_interval: 2000000 # interval in microseconds between service loop checks
cmd_start: bin/console %s -vv -e prod > /dev/null 2>&1 & # template for scheduled commands to be executed with
cmd_kill: kill -2 %s > /dev/null 2>&1 & # template for scheduled commands to be stopped with
storage:
dsn: '%env(DATABASE_URL)%' # dsn for mysql or sqlite database to store schedule
lock: emdrive_lock # lock name that is configured in framework section
pid_dir: var/pid # directory to store process ids for executed commands
log_dir: var/elog # directory to store logs
lock_dir: var/lock # directory to store lock files
framework:
lock:
enabled: true
resources:
emdrive_lock: flock
#emdrive_lock: [flock, 'memcached://localhost'] # incase multiple servers are used to run app
Commands, (*7)
bin/console emdrive:deploy
# main deploy command that detects other deploy commands and executes them in order to deploy bundle, (*8)
bin/console emdrive:deploy:update-schedule
# deploy command to update schedule, (*9)
bin/console emdrive:configure-schedule [<name>]
# change command schedule time/interval, (*10)
bin/console emdrive:service:run
# launch service, (*11)
bin/console emdrive:service:stop
# stop service, (*12)
bin/console emdrive:service:status [--watch]
# check if service is running, (*13)
bin/console emdrive:dump-schedule
# dump schedule to console, (*14)
Example:, (*15)
+----+--------------------------+-------------+---------+---------------------+---------------------+---------------+----------------+
| Id | Name | Server name | Status | Last start at | Next start at | Schedule type | Schedule value |
+----+--------------------------+-------------+---------+---------------------+---------------------+---------------+----------------+
| 1 | first-scheduled-command | main | stopped | 2018-04-06 23:19:01 | 2018-04-06 23:20:01 | interval | 1 minutes |
| 2 | second-scheduled-command | main | stopped | 2018-04-06 23:05:00 | 2018-04-07 23:05:00 | time | 23:05 |
+----+--------------------------+-------------+---------+---------------------+---------------------+---------------+----------------+
Create scheduled command, (*16)
use Emdrive\Command\ScheduledCommandInterface;
use Emdrive\InterruptableExecutionTrait;
use Emdrive\LockableExecutionTrait;
use Symfony\Component\Console\Command\Command;
class FisrtScheduledCommand extends Command implements ScheduledCommandInterface
{
use LockableExecutionTrait;
use InterruptableExecutionTrait;
public function configure()
{
$this->setName('first-scheduled-command');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
...
foreach ($collection as $item) {
if ($this->isInterrupted()) {
break;
}
...
}
}
}
After you have created new scheduled command run deploy:, (*17)
bin/console emdrive:deploy
, (*18)
then configure schedule:, (*19)
bin/console emdrive:configure-schedule first-scheduled-command
, (*20)
Supervisord configuration, (*21)
[program:emdrive]
command=/code/bin/console emdrive:service:run
stderr_logfile = /var/log/supervisor/emdrive.error.log
stdout_logfile = /var/log/supervisor/emdrive.log
stopsignal = INT
Licence, (*22)
This bundle is released under the MIT license., (*23)