-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathContentReleaseManager.php
More file actions
119 lines (103 loc) · 4.7 KB
/
ContentReleaseManager.php
File metadata and controls
119 lines (103 loc) · 4.7 KB
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
<?php
declare(strict_types=1);
namespace Flowpack\DecoupledContentStore;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\RedisInstanceIdentifier;
use Flowpack\DecoupledContentStore\Core\Infrastructure\RedisClientManager;
use Neos\ContentRepository\Domain\Model\Workspace;
use Flowpack\Prunner\ValueObject\JobId;
use Neos\Flow\Annotations as Flow;
use Flowpack\Prunner\PrunnerApiService;
use Flowpack\Prunner\ValueObject\PipelineName;
/**
* @Flow\Scope("singleton")
*/
class ContentReleaseManager
{
/**
* @Flow\Inject
* @var PrunnerApiService
*/
protected $prunnerApiService;
/**
* @Flow\Inject
* @var RedisClientManager
*/
protected $redisClientManager;
/**
* @Flow\InjectConfiguration("configEpoch")
* @var array
*/
protected $configEpochSettings;
const REDIS_CURRENT_RELEASE_KEY = 'contentStore:current';
const NO_PREVIOUS_RELEASE = 'NO_PREVIOUS_RELEASE';
public function startIncrementalContentRelease(string $currentContentReleaseId = null, Workspace $workspace = null, array $additionalVariables = []): ContentReleaseIdentifier
{
$redis = $this->redisClientManager->getPrimaryRedis();
if ($currentContentReleaseId) {
$currentContentReleaseId = $redis->get(self::REDIS_CURRENT_RELEASE_KEY);
}
$contentReleaseId = ContentReleaseIdentifier::create();
// the currentContentReleaseId is not used in any pipeline step in this package, but is a common need in other
// use cases in extensions, e.g. calculating the differences between current and new release
$this->prunnerApiService->schedulePipeline(PipelineName::create('do_content_release'), array_merge($additionalVariables, [
'contentReleaseId' => $contentReleaseId,
'currentContentReleaseId' => $currentContentReleaseId ?: self::NO_PREVIOUS_RELEASE,
'validate' => true,
'workspaceName' => $workspace ? $workspace->getName() : 'live',
'flushContentCache' => false,
]));
return $contentReleaseId;
}
// the validate parameter can be used to intentionally skip the validation step for this release
public function startFullContentRelease(bool $validate = true, string $currentContentReleaseId = null, Workspace $workspace = null, array $additionalVariables = []): ContentReleaseIdentifier
{
$redis = $this->redisClientManager->getPrimaryRedis();
if ($currentContentReleaseId) {
$currentContentReleaseId = $redis->get(self::REDIS_CURRENT_RELEASE_KEY);
}
$contentReleaseId = ContentReleaseIdentifier::create();
$this->prunnerApiService->schedulePipeline(PipelineName::create('do_content_release'), array_merge($additionalVariables, [
'contentReleaseId' => $contentReleaseId,
'currentContentReleaseId' => $currentContentReleaseId ?: self::NO_PREVIOUS_RELEASE,
'validate' => $validate,
'workspaceName' => $workspace ? $workspace->getName() : 'live',
'flushContentCache' => true,
]));
return $contentReleaseId;
}
public function cancelAllRunningContentReleases(): void
{
$result = $this->prunnerApiService->loadPipelinesAndJobs();
$runningJobs = $result->getJobs()->forPipeline(PipelineName::create('do_content_release'))->running();
foreach ($runningJobs as $job) {
$this->prunnerApiService->cancelJob($job);
}
}
/**
* Cancel a single running content release ignoring all others
*/
public function cancelRunningContentRelease(JobId $jobId): void
{
$result = $this->prunnerApiService->loadPipelinesAndJobs();
$runningJobs = $result->getJobs()->forPipeline(PipelineName::create('do_content_release'))->running();
foreach ($runningJobs as $job) {
if ($job->getId() === $jobId) {
$this->prunnerApiService->cancelJob($job);
break;
}
}
}
public function toggleConfigEpoch(RedisInstanceIdentifier $redisInstanceIdentifier): void
{
$currentConfigEpochConfig = $this->configEpochSettings['current'] ?? null;
$previousConfigEpochConfig = $this->configEpochSettings['previous'] ?? null;
$redis = $this->redisClientManager->getRedis($redisInstanceIdentifier);
$configEpochRedis = $redis->get('contentStore:configEpoch');
if ($configEpochRedis === $currentConfigEpochConfig) {
$redis->set('contentStore:configEpoch', $previousConfigEpochConfig);
} else {
$redis->set('contentStore:configEpoch', $currentConfigEpochConfig);
}
}
}