|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Level23\Druid\Tasks; |
|
5
|
|
|
|
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
use Level23\Druid\DruidClient; |
|
8
|
|
|
use Level23\Druid\Context\TaskContext; |
|
9
|
|
|
use Level23\Druid\Concerns\HasInterval; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class KillTaskBuilder |
|
13
|
|
|
* |
|
14
|
|
|
* This class allows you to build a kill task. A kill task will delete all unused segments |
|
15
|
|
|
* between the given intervals. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Level23\Druid\Tasks |
|
18
|
|
|
*/ |
|
19
|
|
|
class KillTaskBuilder extends TaskBuilder |
|
20
|
|
|
{ |
|
21
|
|
|
use HasInterval; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected string $dataSource; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* If markAsUnused is true (default is false), the kill task will first mark any segments within the specified |
|
30
|
|
|
* interval as unused, before deleting the unused segments within the interval. |
|
31
|
|
|
* |
|
32
|
|
|
* @var bool |
|
33
|
|
|
*/ |
|
34
|
|
|
protected bool $markAsUnused = false; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* IndexTaskBuilder constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Level23\Druid\DruidClient $druidClient |
|
40
|
|
|
* @param string $dataSource Data source where you want to delete unused segments for. |
|
41
|
|
|
*/ |
|
42
|
8 |
|
public function __construct(DruidClient $druidClient, string $dataSource) |
|
43
|
|
|
{ |
|
44
|
8 |
|
$this->client = $druidClient; |
|
45
|
8 |
|
$this->dataSource = $dataSource; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* If markAsUnused is true, the kill task will first mark any segments within the specified |
|
50
|
|
|
* interval as unused, before deleting the unused segments within the interval. |
|
51
|
|
|
* |
|
52
|
|
|
* When calling this method, you can set the `markAsUnused` property. If no parameter specified, we will set it |
|
53
|
|
|
* to true. The default setting for markAsUnused is false. |
|
54
|
|
|
* |
|
55
|
|
|
* @param bool $markAsUnused |
|
56
|
|
|
* |
|
57
|
|
|
* @return $this |
|
58
|
|
|
*/ |
|
59
|
7 |
|
public function markAsUnused(bool $markAsUnused = true): KillTaskBuilder |
|
60
|
|
|
{ |
|
61
|
7 |
|
$this->markAsUnused = $markAsUnused; |
|
62
|
|
|
|
|
63
|
7 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @inheritDoc |
|
68
|
|
|
*/ |
|
69
|
7 |
|
protected function buildTask(array|TaskContext $context): TaskInterface |
|
70
|
|
|
{ |
|
71
|
7 |
|
if ($this->interval === null) { |
|
72
|
1 |
|
throw new InvalidArgumentException('You have to specify an interval!'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
6 |
|
if (!$context instanceof TaskContext) { |
|
|
|
|
|
|
76
|
6 |
|
$context = new TaskContext($context); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
6 |
|
return new KillTask($this->dataSource, $this->interval, $this->taskId, $context, $this->markAsUnused); |
|
80
|
|
|
} |
|
81
|
|
|
} |