Skip to content

Commit

Permalink
Added stopping of docker containers when ExApp is disabling. Timeout …
Browse files Browse the repository at this point in the history
…of enable/disable increased to 60. (#430)

If ExApp is resource-heavy, stopping it now does not always free up
resources (only if it is implemented in ExApp itself, which is quite
rare)

That is why we add this PR to turn off the docker container when
clicking the "disable" button on ExApp.

With "manual installation" - nothing changes, we have nothing to turn
off and this is not supported.


Also, the timeout for a request to ExApp to turn on/off has been raised
from **30 seconds to 60 seconds**, which is still acceptable for UI so
as not to seem slow;


Resolves: #410

Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 authored Oct 31, 2024
1 parent b52fbc3 commit 92f2f87
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct(
private readonly DockerActions $dockerActions,
private readonly ManualActions $manualActions,
private readonly AppAPICommonService $commonService,
private readonly DaemonConfigService $daemonConfigService,
) {
$this->client = $clientService->newClient();
}
Expand Down Expand Up @@ -556,7 +557,13 @@ public function getExAppDomain(ExApp $exApp): string {
*/
public function enableExApp(ExApp $exApp): bool {
if ($this->exAppService->enableExAppInternal($exApp)) {
$exAppEnabled = $this->requestToExApp($exApp, '/enabled?enabled=1', null, 'PUT', options: ['timeout' => 30]);
if ($exApp->getAcceptsDeployId() === $this->dockerActions->getAcceptsDeployId()) {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($exApp->getDaemonConfigName());
$this->dockerActions->initGuzzleClient($daemonConfig);
$this->dockerActions->startContainer($this->dockerActions->buildDockerUrl($daemonConfig), $this->dockerActions->buildExAppContainerName($exApp->getAppid()));
}

$exAppEnabled = $this->requestToExApp($exApp, '/enabled?enabled=1', null, 'PUT', options: ['timeout' => 60]);
if ($exAppEnabled instanceof IResponse) {
$response = json_decode($exAppEnabled->getBody(), true);
if (!empty($response['error'])) {
Expand All @@ -579,7 +586,7 @@ public function enableExApp(ExApp $exApp): bool {
*/
public function disableExApp(ExApp $exApp): bool {
$result = true;
$exAppDisabled = $this->requestToExApp($exApp, '/enabled?enabled=0', null, 'PUT', options: ['timeout' => 30]);
$exAppDisabled = $this->requestToExApp($exApp, '/enabled?enabled=0', null, 'PUT', options: ['timeout' => 60]);
if ($exAppDisabled instanceof IResponse) {
$response = json_decode($exAppDisabled->getBody(), true);
if (isset($response['error']) && strlen($response['error']) !== 0) {
Expand All @@ -590,6 +597,11 @@ public function disableExApp(ExApp $exApp): bool {
$this->logger->error(sprintf('Failed to disable ExApp %s. Error: %s', $exApp->getAppid(), $exAppDisabled['error']));
$result = false;
}
if ($exApp->getAcceptsDeployId() === $this->dockerActions->getAcceptsDeployId()) {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($exApp->getDaemonConfigName());
$this->dockerActions->initGuzzleClient($daemonConfig);
$this->dockerActions->stopContainer($this->dockerActions->buildDockerUrl($daemonConfig), $this->dockerActions->buildExAppContainerName($exApp->getAppid()));
}
$this->exAppService->disableExAppInternal($exApp);
return $result;
}
Expand Down

0 comments on commit 92f2f87

Please sign in to comment.