Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter pattern #142

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Adapter pattern #142

wants to merge 4 commits into from

Conversation

basert
Copy link

@basert basert commented Feb 20, 2025

This moves runner related code into an adapter.

@basert basert force-pushed the adapter-pattern branch 13 times, most recently from e90bc74 to 29e16c8 Compare February 20, 2025 15:29
// Wait for runtime
for ($i = 0; $i < 10; $i++) {
$output = '';
$code = Console::execute('docker container inspect ' . \escapeshellarg($runtimeName), '', $output);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange I thought we used the Docker API here? Doesn't the Docker() adapter have this method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param Log $log
* @return mixed
*/
abstract public function createExecution(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the difference between createRuntime and createExecution? Are they not the same?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createRuntime is called by:

Http::post('/v1/runtimes')
    ->desc("Create a new runtime server")

createExecution is called by:

Http::post('/v1/runtimes/:runtimeId/executions')
    ->alias('/v1/runtimes/:runtimeId/execution')
    ->desc('Create an execution')

A runtime can be used by the execution, e.g. in Kubernetes it calls itself internally. Here I just moved the http.php code into different functions.

case Storage::DEVICE_LOCAL:
default:
return new Local($root);
case Storage::DEVICE_S3:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be a good chance to migrate this to DSN format like we do for databases. Will also make it easier to handle any new adapters and maintenance in general.

* @param Table $statsContainers
* @return void
*/
public function init(Table $activeRuntimes, array $networks, Table $statsHost, Table $statsContainers): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need to handle state like this also in the other adapter? If we do, can we have a parent class that handles this on a higher level? This will help us make adapters leaner and avoid having to pass this knowledge/tasks between adapters.

Can we also move this logic to the constructor instead of having an init method?

* @param Table $statsContainers
* @return void
*/
public function init(Table $activeRuntimes, array $networks, Table $statsHost, Table $statsContainers): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another ideas is to maybe place the state management on the server level and this way isolate all the swoole related stuff from this layer. It will make upgrading server version easier, especially with the planned move to the new coroutine version in a few weeks/months.

@basert basert force-pushed the adapter-pattern branch 5 times, most recently from ae70b10 to 6370516 Compare February 26, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants