|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Level23\Druid\Tasks; |
|
5
|
|
|
|
|
6
|
|
|
use Level23\Druid\Interval\Interval; |
|
7
|
|
|
use Level23\Druid\Context\TaskContext; |
|
8
|
|
|
|
|
9
|
|
|
class KillTask implements TaskInterface |
|
10
|
|
|
{ |
|
11
|
|
|
protected string $dataSource; |
|
12
|
|
|
|
|
13
|
|
|
protected ?string $taskId; |
|
14
|
|
|
|
|
15
|
|
|
protected Interval $interval; |
|
16
|
|
|
|
|
17
|
|
|
protected ?TaskContext $context; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* If markAsUnused is true (default is false), the kill task will first mark any segments within the specified |
|
21
|
|
|
* interval as unused, before deleting the unused segments within the interval. |
|
22
|
|
|
* |
|
23
|
|
|
* @var bool |
|
24
|
|
|
*/ |
|
25
|
|
|
protected bool $markAsUnused; |
|
26
|
|
|
|
|
27
|
12 |
|
public function __construct( |
|
28
|
|
|
string $dataSource, |
|
29
|
|
|
Interval $interval, |
|
30
|
|
|
?string $taskId = null, |
|
31
|
|
|
?TaskContext $context = null, |
|
32
|
|
|
bool $markAsUnused = false |
|
33
|
|
|
) { |
|
34
|
12 |
|
$this->dataSource = $dataSource; |
|
35
|
12 |
|
$this->taskId = $taskId; |
|
36
|
12 |
|
$this->interval = $interval; |
|
37
|
12 |
|
$this->context = $context; |
|
38
|
12 |
|
$this->markAsUnused = $markAsUnused; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Return the task in a format so that we can send it to druid. |
|
43
|
|
|
* |
|
44
|
|
|
* @return array<string,string|bool|array<string,string|int|bool>> |
|
45
|
|
|
*/ |
|
46
|
12 |
|
public function toArray(): array |
|
47
|
|
|
{ |
|
48
|
12 |
|
$result = [ |
|
49
|
12 |
|
'type' => 'kill', |
|
50
|
12 |
|
'dataSource' => $this->dataSource, |
|
51
|
12 |
|
'interval' => $this->interval->getInterval(), |
|
52
|
12 |
|
'markAsUnused' => $this->markAsUnused, |
|
53
|
12 |
|
]; |
|
54
|
|
|
|
|
55
|
12 |
|
if ($this->taskId) { |
|
56
|
6 |
|
$result['id'] = $this->taskId; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
12 |
|
$context = $this->context ? $this->context->toArray() : []; |
|
60
|
12 |
|
if (count($context) > 0) { |
|
61
|
3 |
|
$result['context'] = $context; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
12 |
|
return $result; |
|
65
|
|
|
} |
|
66
|
|
|
} |