generated from codenamephp/template.php.library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bastian Schwarz <[email protected]>
- Loading branch information
Bastian Schwarz
committed
May 13, 2023
1 parent
debd85e
commit c40c375
Showing
17 changed files
with
428 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright 2023 Bastian Schwarz <[email protected]>. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
docker compose exec -it -u application application bash -c "$*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* Copyright 2023 Bastian Schwarz <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace de\codenamephp\deploymentchecks\async\Check\Factory\FromCheck; | ||
|
||
use de\codenamephp\deploymentchecks\async\Check\ParallelCheckInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\CheckInterface; | ||
|
||
/** | ||
* Interface to create parallel checks from a regular check on the fly | ||
*/ | ||
interface FromCheckFactoryInterface | ||
{ | ||
|
||
public function build(CheckInterface $check): ParallelCheckInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* Copyright 2023 Bastian Schwarz <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace de\codenamephp\deploymentchecks\async\Check\Factory\FromCheck; | ||
|
||
use de\codenamephp\deploymentchecks\async\Check\ParallelCheckInterface; | ||
use de\codenamephp\deploymentchecks\async\Check\ParallelCheckWithErrorHandler; | ||
use de\codenamephp\deploymentchecks\async\ErrorHandler\ErrorHandlerInterface; | ||
use de\codenamephp\deploymentchecks\async\ErrorHandler\RethrowException; | ||
use de\codenamephp\deploymentchecks\async\SuccessHandler\AddToResultCollection; | ||
use de\codenamephp\deploymentchecks\async\SuccessHandler\SuccessHandlerInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\CheckInterface; | ||
|
||
/** | ||
* Factory to create ParallelCheckWithErrorHandler instances | ||
* | ||
* @psalm-api | ||
*/ | ||
final class WithErrorHandlerFactory implements FromCheckFactoryInterface | ||
{ | ||
public function __construct( | ||
public SuccessHandlerInterface $successHandler = new AddToResultCollection(), | ||
public ErrorHandlerInterface $errorHandler = new RethrowException(), | ||
) {} | ||
|
||
public function build(CheckInterface $check): ParallelCheckInterface | ||
{ | ||
return new ParallelCheckWithErrorHandler($check, $this->successHandler, $this->errorHandler); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* Copyright 2023 Bastian Schwarz <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace de\codenamephp\deploymentchecks\async\Check; | ||
|
||
use de\codenamephp\deploymentchecks\async\SuccessHandler\SuccessHandlerInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\Result\ResultInterface; | ||
|
||
/** | ||
* Interface for checks that can be used in parallel using the async pool | ||
*/ | ||
interface ParallelCheckInterface | ||
{ | ||
|
||
/** | ||
* Since the async pool only accepts callables, this method is used to invoke the check and return the result | ||
* | ||
* @return ResultInterface | ||
*/ | ||
public function __invoke(): ResultInterface; | ||
|
||
/** | ||
* Gets the success handler that is used to handle the result if the check was successful | ||
* | ||
* @return SuccessHandlerInterface | ||
*/ | ||
public function successHandler(): SuccessHandlerInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* Copyright 2023 Bastian Schwarz <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace de\codenamephp\deploymentchecks\async\Check; | ||
|
||
use de\codenamephp\deploymentchecks\async\ErrorHandler\ErrorHandlerInterface; | ||
use de\codenamephp\deploymentchecks\async\ErrorHandler\RethrowException; | ||
use de\codenamephp\deploymentchecks\async\SuccessHandler\AddToResultCollection; | ||
use de\codenamephp\deploymentchecks\async\SuccessHandler\SuccessHandlerInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\CheckInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\Result\ResultInterface; | ||
|
||
/** | ||
* Basically a wrapper around a check that implements the ParallelCheckInterface and WithErrorHandlerInterface. The spatie async pool expects a callable so this | ||
* class implements that interface and just calls the check. The check itself is passed in the constructor and the success and error handler are optional. | ||
* | ||
* The default AsyncCheckCollection will use this check to run the checks in parallel. It will use the success and error handler as quasi callbacks to handle the result | ||
* of the check. | ||
* | ||
* The default success handler will add the result to the result collection and the default error handler will rethrow the exception. | ||
*/ | ||
final readonly class ParallelCheckWithErrorHandler implements ParallelCheckInterface, WithErrorHandlerInterface | ||
{ | ||
|
||
public function __construct( | ||
public CheckInterface $check, | ||
public SuccessHandlerInterface $successHandler = new AddToResultCollection(), | ||
public ErrorHandlerInterface $errorHandler = new RethrowException(), | ||
) {} | ||
|
||
public function __invoke(): ResultInterface | ||
{ | ||
return $this->check->run(); | ||
} | ||
|
||
public function successHandler(): SuccessHandlerInterface | ||
{ | ||
return $this->successHandler; | ||
} | ||
|
||
public function errorHandler(): ErrorHandlerInterface | ||
{ | ||
return $this->errorHandler; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* Copyright 2023 Bastian Schwarz <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace de\codenamephp\deploymentchecks\async\Check; | ||
|
||
use de\codenamephp\deploymentchecks\async\ErrorHandler\ErrorHandlerInterface; | ||
|
||
/** | ||
* Interface for parallel checks that want to define a custom error handler | ||
*/ | ||
interface WithErrorHandlerInterface | ||
{ | ||
|
||
public function errorHandler(): ErrorHandlerInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* Copyright 2023 Bastian Schwarz <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace de\codenamephp\deploymentchecks\async\Collection; | ||
|
||
use de\codenamephp\deploymentchecks\async\Check\Factory\FromCheck\FromCheckFactoryInterface; | ||
use de\codenamephp\deploymentchecks\async\Check\WithErrorHandlerInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\CheckInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollectionInterface; | ||
use de\codenamephp\deploymentchecks\base\Check\Result\ResultInterface; | ||
use Spatie\Async\Pool; | ||
use Throwable; | ||
|
||
/** | ||
* @psalm-api | ||
*/ | ||
final readonly class AsyncCheckCollection implements CheckInterface | ||
{ | ||
|
||
/** | ||
* @var array<CheckInterface> | ||
*/ | ||
public array $checks; | ||
|
||
public function __construct( | ||
public Pool $pool, | ||
public ResultCollectionInterface $resultCollection, | ||
public FromCheckFactoryInterface $fromCheckFactory, | ||
CheckInterface ...$checks) | ||
{ | ||
$this->checks = $checks; | ||
} | ||
|
||
public function run(): ResultInterface | ||
{ | ||
foreach ($this->checks as $check) { | ||
$parallelCheck = $this->fromCheckFactory->build($check); | ||
$runnable = $this->pool | ||
->add($parallelCheck) | ||
->then(fn(ResultInterface $output) => $parallelCheck->successHandler()->handle($this->resultCollection, $output)); | ||
if ($parallelCheck instanceof WithErrorHandlerInterface) $runnable->catch(fn(Throwable $exception): mixed => $parallelCheck->errorHandler()->handle($this->resultCollection, $exception)); | ||
} | ||
$this->pool->wait(); | ||
return $this->resultCollection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* Copyright 2023 Bastian Schwarz <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace de\codenamephp\deploymentchecks\async\ErrorHandler; | ||
|
||
use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollectionInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Interface for a simple error handler. It expects the result collection build in the async collection and the exception that was thrown. | ||
*/ | ||
interface ErrorHandlerInterface | ||
{ | ||
|
||
public function handle(ResultCollectionInterface $resultCollection, Throwable $exception): mixed; | ||
} |
Oops, something went wrong.