-
Notifications
You must be signed in to change notification settings - Fork 1
/
WorkerInterface.php
121 lines (109 loc) · 3.58 KB
/
WorkerInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace Aternos\Taskmaster\Worker;
use Aternos\Taskmaster\Proxy\ProxyInterface;
use Aternos\Taskmaster\Runtime\RuntimeInterface;
use Aternos\Taskmaster\Task\TaskFactoryInterface;
use Aternos\Taskmaster\Task\TaskInterface;
use Aternos\Taskmaster\Taskmaster;
use Aternos\Taskmaster\TaskmasterOptions;
use Aternos\Taskmaster\Worker\Instance\WorkerInstanceInterface;
/**
* Interface WorkerInterface
*
* A worker runs tasks in a {@link RuntimeInterface}.
* It starts a {@link WorkerInstanceInterface} when necessary and assigns tasks to it.
* When the worker instance dies, the worker will start a new one.
* The worker can use a {@link ProxyInterface} to run the worker instance.
*
* @package Aternos\Taskmaster\Worker
*/
interface WorkerInterface
{
/**
* Get the worker group
*
* The worker group can be used to assign tasks to specific workers
* by setting the same group on the worker and the task.
*
* @return string|null
*/
public function getGroup(): ?string;
/**
* Get the current proxy
*
* The taskmaster will get the proxy, start and update it when necessary.
*
* @return ProxyInterface|null
*/
public function getProxy(): ?ProxyInterface;
/**
* Set the taskmaster options
*
* If the options are not set, the taskmaster will set the default options.
*
* @param TaskmasterOptions $options
* @return $this
*/
public function setOptions(TaskmasterOptions $options): static;
/**
* Set the taskmaster options if necessary
*
* If the options are already set, they will not be overwritten.
* This is called by {@link Taskmaster::addWorker()}.
* If you want to set different options, e.g. a different PHP binary, call this before adding the worker.
*
* @param TaskmasterOptions $options
* @return $this
*/
public function setOptionsIfNecessary(TaskmasterOptions $options): static;
/**
* Set the init task factory for the worker
*
* Init tasks are executed once as first task on every worker instance to initialize the worker.
*
* @param TaskFactoryInterface|null $initTaskFactory
* @return $this
*/
public function setInitTaskFactory(?TaskFactoryInterface $initTaskFactory): static;
/**
* Set the init task factory for the worker if necessary
*
* If the init task factory is already set, it will not be overwritten.
* This is called by {@link Taskmaster::addWorker()}.
* If you want to set a different init task factory, call this before adding the worker.
*
* @param TaskFactoryInterface|null $initTaskFactory
* @return $this
*/
public function setInitTaskFactoryIfNecessary(?TaskFactoryInterface $initTaskFactory): static;
/**
* Update the worker and its instance
*
* @return $this
*/
public function update(): static;
/**
* Stop the worker and its instance
*
* @return $this
*/
public function stop(): static;
/**
* Get the worker status
*
* @return WorkerStatus
* @see WorkerStatus
*/
public function getStatus(): WorkerStatus;
/**
* Assign a task to the worker
*
* This doesn't mean that the task will be executed immediately, because the instance might need to be
* started first. But the worker should change its status to {@link WorkerStatus::WORKING} immediately
* to avoid getting assigned more tasks.
*
* @param TaskInterface $task
* @return $this
*/
public function assignTask(TaskInterface $task): static;
}