2021-03-24 17:02:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
2021-11-30 15:10:01 +08:00
|
|
|
namespace Note;
|
2021-03-24 17:02:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
use Exception;
|
2021-08-11 01:04:57 +08:00
|
|
|
use Kiri\Kiri;
|
2021-11-30 14:59:51 +08:00
|
|
|
use Server\Tasker\AsyncTaskExecute;
|
2021-03-24 17:02:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-30 14:59:51 +08:00
|
|
|
* Class Task
|
2021-11-30 15:10:01 +08:00
|
|
|
* @package Note
|
2021-03-24 17:02:12 +08:00
|
|
|
* Task任务
|
|
|
|
|
*/
|
2021-11-30 14:59:51 +08:00
|
|
|
#[\Attribute(\Attribute::TARGET_CLASS)] class Task extends Attribute
|
2021-03-24 17:02:12 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-30 14:59:51 +08:00
|
|
|
* Task constructor.
|
2021-03-24 17:02:12 +08:00
|
|
|
* @param string $name
|
|
|
|
|
*/
|
2021-08-29 05:53:47 +08:00
|
|
|
public function __construct(public string $name)
|
2021-03-24 17:02:12 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-12 17:17:36 +08:00
|
|
|
* @param mixed $class
|
|
|
|
|
* @param mixed|null $method
|
2021-03-24 17:02:12 +08:00
|
|
|
* @return bool
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-08-29 05:53:47 +08:00
|
|
|
public function execute(mixed $class, mixed $method = null): bool
|
2021-07-12 17:17:36 +08:00
|
|
|
{
|
2021-11-30 14:59:51 +08:00
|
|
|
$task = Kiri::getDi()->get(AsyncTaskExecute::class);
|
|
|
|
|
$task->reg($this->name, $class);
|
2021-03-24 17:02:12 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|