2018-01-26 16:39:31 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of the Magallanes package.
|
|
|
|
*
|
|
|
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Mage\Task\BuiltIn;
|
|
|
|
|
|
|
|
use Mage\Task\Exception\ErrorException;
|
|
|
|
use Mage\Task\AbstractTask;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sleep task. Sleeps for a given number of seconds so you can delay task
|
|
|
|
* execution.
|
|
|
|
*
|
|
|
|
* @author Yanick Witschi <https://github.com/Toflar>
|
|
|
|
*/
|
|
|
|
class SleepTask extends AbstractTask
|
|
|
|
{
|
2022-04-10 23:13:59 +02:00
|
|
|
public function getName(): string
|
2018-01-26 16:39:31 +01:00
|
|
|
{
|
|
|
|
return 'sleep';
|
|
|
|
}
|
|
|
|
|
2022-04-10 23:13:59 +02:00
|
|
|
public function getDescription(): string
|
2018-01-26 16:39:31 +01:00
|
|
|
{
|
|
|
|
$options = $this->getOptions();
|
|
|
|
|
2022-04-10 23:13:59 +02:00
|
|
|
return sprintf('[Sleep] Sleeping for %d second(s)', $options['seconds']);
|
2018-01-26 16:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws ErrorException
|
|
|
|
*/
|
2022-04-10 23:13:59 +02:00
|
|
|
public function execute(): bool
|
2018-01-26 16:39:31 +01:00
|
|
|
{
|
|
|
|
$options = $this->getOptions();
|
|
|
|
|
2022-04-10 23:13:59 +02:00
|
|
|
sleep(intval($options['seconds']));
|
2018-01-26 16:39:31 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-04-10 23:13:59 +02:00
|
|
|
* @return array<string, string|int>
|
2018-01-26 16:39:31 +01:00
|
|
|
*/
|
2022-04-10 23:13:59 +02:00
|
|
|
protected function getOptions(): array
|
2018-01-26 16:39:31 +01:00
|
|
|
{
|
|
|
|
$options = array_merge(
|
|
|
|
['seconds' => 1],
|
|
|
|
$this->options
|
|
|
|
);
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
}
|