44
55namespace Flowpack \DecoupledContentStore ;
66
7+ use Flowpack \DecoupledContentStore \Core \Domain \ValueObject \ContentReleaseIdentifier ;
78use Flowpack \DecoupledContentStore \Core \Domain \ValueObject \RedisInstanceIdentifier ;
89use Flowpack \DecoupledContentStore \Core \Infrastructure \RedisClientManager ;
10+ use Neos \ContentRepository \Domain \Model \Workspace ;
11+ use Flowpack \Prunner \ValueObject \JobId ;
912use Neos \Flow \Annotations as Flow ;
1013use Flowpack \Prunner \PrunnerApiService ;
1114use Flowpack \Prunner \ValueObject \PipelineName ;
@@ -43,27 +46,45 @@ class ContentReleaseManager
4346 const REDIS_CURRENT_RELEASE_KEY = 'contentStore:current ' ;
4447 const NO_PREVIOUS_RELEASE = 'NO_PREVIOUS_RELEASE ' ;
4548
46- public function startIncrementalContentRelease ()
49+ public function startIncrementalContentRelease (string $ currentContentReleaseId = null , Workspace $ workspace = null , array $ additionalVariables = []): ContentReleaseIdentifier
4750 {
4851 $ redis = $ this ->redisClientManager ->getPrimaryRedis ();
49- $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
52+ if ($ currentContentReleaseId ) {
53+ $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
54+ }
5055
56+ $ contentReleaseId = ContentReleaseIdentifier::create ();
5157 // the currentContentReleaseId is not used in any pipeline step in this package, but is a common need in other
5258 // use cases in extensions, e.g. calculating the differences between current and new release
53- $ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), ['contentReleaseId ' => (string )time (), 'currentContentReleaseId ' => $ currentContentReleaseId ?: self ::NO_PREVIOUS_RELEASE , 'validate ' => true ]);
59+ $ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), array_merge ($ additionalVariables , [
60+ 'contentReleaseId ' => $ contentReleaseId ,
61+ 'currentContentReleaseId ' => $ currentContentReleaseId ?: self ::NO_PREVIOUS_RELEASE ,
62+ 'validate ' => true ,
63+ 'workspaceName ' => $ workspace ? $ workspace ->getName () : 'live ' ,
64+ ]));
65+ return $ contentReleaseId ;
5466 }
5567
5668 // the validate parameter can be used to intentionally skip the validation step for this release
57- public function startFullContentRelease (bool $ validate = true )
69+ public function startFullContentRelease (bool $ validate = true , string $ currentContentReleaseId = null , Workspace $ workspace = null , array $ additionalVariables = []): ContentReleaseIdentifier
5870 {
5971 $ redis = $ this ->redisClientManager ->getPrimaryRedis ();
60- $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
72+ if ($ currentContentReleaseId ) {
73+ $ currentContentReleaseId = $ redis ->get (self ::REDIS_CURRENT_RELEASE_KEY );
74+ }
6175
76+ $ contentReleaseId = ContentReleaseIdentifier::create ();
6277 $ this ->contentCache ->flush ();
63- $ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), ['contentReleaseId ' => (string )time (), 'currentContentReleaseId ' => $ currentContentReleaseId ?: self ::NO_PREVIOUS_RELEASE , 'validate ' => $ validate ]);
78+ $ this ->prunnerApiService ->schedulePipeline (PipelineName::create ('do_content_release ' ), array_merge ($ additionalVariables , [
79+ 'contentReleaseId ' => $ contentReleaseId ,
80+ 'currentContentReleaseId ' => $ currentContentReleaseId ?: self ::NO_PREVIOUS_RELEASE ,
81+ 'validate ' => $ validate ,
82+ 'workspaceName ' => $ workspace ? $ workspace ->getName () : 'live ' ,
83+ ]));
84+ return $ contentReleaseId ;
6485 }
6586
66- public function cancelAllRunningContentReleases ()
87+ public function cancelAllRunningContentReleases (): void
6788 {
6889 $ result = $ this ->prunnerApiService ->loadPipelinesAndJobs ();
6990 $ runningJobs = $ result ->getJobs ()->forPipeline (PipelineName::create ('do_content_release ' ))->running ();
@@ -72,7 +93,22 @@ public function cancelAllRunningContentReleases()
7293 }
7394 }
7495
75- public function toggleConfigEpoch (RedisInstanceIdentifier $ redisInstanceIdentifier )
96+ /**
97+ * Cancel a single running content release ignoring all others
98+ */
99+ public function cancelRunningContentRelease (JobId $ jobId ): void
100+ {
101+ $ result = $ this ->prunnerApiService ->loadPipelinesAndJobs ();
102+ $ runningJobs = $ result ->getJobs ()->forPipeline (PipelineName::create ('do_content_release ' ))->running ();
103+ foreach ($ runningJobs as $ job ) {
104+ if ($ job ->getId () === $ jobId ) {
105+ $ this ->prunnerApiService ->cancelJob ($ job );
106+ break ;
107+ }
108+ }
109+ }
110+
111+ public function toggleConfigEpoch (RedisInstanceIdentifier $ redisInstanceIdentifier ): void
76112 {
77113 $ currentConfigEpochConfig = $ this ->configEpochSettings ['current ' ] ?? null ;
78114 $ previousConfigEpochConfig = $ this ->configEpochSettings ['previous ' ] ?? null ;
0 commit comments