| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Scheduler\Contract; |
| 4 |
|
| 5 |
use Ramsey\Uuid\UuidInterface; |
| 6 |
use React\Promise\PromiseInterface; |
| 7 |
|
| 8 |
/** |
| 9 |
* Contract for a schedulable task |
| 10 |
* |
| 11 |
* A task encapsulates a named, uniquely identified unit of work that the |
| 12 |
* scheduler can execute via {@see Task::run()}. |
| 13 |
*/ |
| 14 |
interface Task |
| 15 |
{ |
| 16 |
/** |
| 17 |
* Get the name of this task |
| 18 |
* |
| 19 |
* @return string |
| 20 |
*/ |
| 21 |
public function getName(): string; |
| 22 |
|
| 23 |
/** |
| 24 |
* Get unique identifier of this task |
| 25 |
* |
| 26 |
* @return UuidInterface |
| 27 |
*/ |
| 28 |
public function getUuid(): UuidInterface; |
| 29 |
|
| 30 |
/** |
| 31 |
* Get the description of this task |
| 32 |
* |
| 33 |
* @return ?string |
| 34 |
*/ |
| 35 |
public function getDescription(): ?string; |
| 36 |
|
| 37 |
/** |
| 38 |
* Execute this task and return a promise for the result |
| 39 |
* |
| 40 |
* There are two valid implementation patterns: |
| 41 |
* |
| 42 |
* - Async: commit work to the event loop and return a *pending* promise |
| 43 |
* that resolves or rejects upon completion. This is the preferred pattern |
| 44 |
* for I/O-bound or long-running work. |
| 45 |
* |
| 46 |
* - Synchronous: return an already-resolved or already-rejected promise |
| 47 |
* when the result is known immediately (e.g. from cache or trivial logic). |
| 48 |
* |
| 49 |
* Either way, implementations MUST NOT perform blocking I/O or CPU-intensive |
| 50 |
* work that would stall the event loop. |
| 51 |
* |
| 52 |
* @return PromiseInterface<mixed> |
| 53 |
*/ |
| 54 |
public function run(): PromiseInterface; |
| 55 |
} |