Skip to content

Commit

Permalink
app init status logic adjustments
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Borysenko <[email protected]>
  • Loading branch information
andrey18106 committed Oct 19, 2023
1 parent b7830ae commit 7d3c9ed
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
12 changes: 12 additions & 0 deletions lib/Command/ExApp/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->service->dispatchExAppInit($exApp);

if ($daemonConfig->getAcceptsDeployId() === $this->manualActions->getAcceptsDeployId()) {
// Wait until ExApp initialized in case of manual-install type
do {
$exApp = $this->service->getExApp($appId);
$status = json_decode($exApp->getStatus(), true);
if (isset($status['error'])) {
$output->writeln(sprintf('ExApp %s initialization step failed. Error: %s', $appId, $status['error']));
return 1;
}
} while (isset($status['progress']));
}

$output->writeln(sprintf('ExApp %s successfully registered.', $appId));
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions lib/Command/ExApp/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$this->service->setAppInitProgress($appId, 0, '', true);
$this->service->dispatchExAppInit($exApp);

$output->writeln(sprintf('ExApp %s successfully updated.', $appId));
Expand Down
4 changes: 1 addition & 3 deletions lib/Controller/ExAppsPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use OC\App\Platform;
use OC_App;
use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Attribute\AppAPIAuth;
use OCA\AppAPI\Db\DaemonConfig;
use OCA\AppAPI\Db\ExApp;
use OCA\AppAPI\Db\ExAppScope;
Expand All @@ -26,7 +25,6 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
Expand Down Expand Up @@ -663,7 +661,7 @@ public function updateApp(string $appId): JSONResponse {
'port' => (int) $exAppInfo['port'],
])) {
// 6. Set initialization progress to start
$this->service->setAppInitProgress($appId, 0);
$this->service->setAppInitProgress($appId, 0, '', true);
// 7. Dispatch init step on ExApp side
$this->service->dispatchExAppInit($exApp);
}
Expand Down
8 changes: 2 additions & 6 deletions lib/Controller/OCSApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,8 @@ public function getNCUsersList(): DataResponse {
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function setAppProgress(string $appId, int $progress): DataResponse {
$this->service->setAppInitProgress($appId, $progress);
if ($progress === 100) {
$exApp = $this->service->getExApp($appId);
$this->service->enableExApp($exApp);
}
public function setAppProgress(string $appId, int $progress, string $error): DataResponse {
$this->service->setAppInitProgress($appId, $progress, $error);
return new DataResponse();
}
}
24 changes: 20 additions & 4 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,28 @@ public function updateExAppInfo(ExApp $exApp, array $exAppInfo): bool {
*
* @return void
*/
public function setAppInitProgress(string $appId, int $progress): void {
public function setAppInitProgress(string $appId, int $progress, string $error = '', bool $update = false): void {
$exApp = $this->getExApp($appId);
$cacheKey = '/exApp_' . $exApp->getAppid();

$status = json_decode($exApp->getStatus(), true);

if ($update) {
// Set active=false during update action, for register it already false
$status['active'] = false;
}

if ($status['active']) {
return;
}

if ($progress === -1) {
$this->logger->error(sprintf('ExApp %s initialization failed', $appId));
$this->logger->error(sprintf('ExApp %s initialization failed. Error: %s', $appId, $error));
if ($error !== '') {
$status['error'] = $error;
}
}
if ($progress < 100 && $progress >= 0) {
if ($progress >= 0 && $progress < 100) {
$status['progress'] = $progress;
} else {
unset($status['progress']);
Expand All @@ -330,9 +343,12 @@ public function setAppInitProgress(string $appId, int $progress): void {
$exApp->setStatus(json_encode($status));

try {
$this->exAppMapper->update($exApp);
$exApp = $this->exAppMapper->update($exApp);
$this->updateExAppLastCheckTime($exApp);
$this->cache->set($cacheKey, $exApp, self::CACHE_TTL);
if ($progress === 100) {
$this->enableExApp($exApp);
}
} catch (Exception) {
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/store/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ const actions = {
context.commit('setIntervalUpdater', null)
}
}
if (Object.hasOwn(state, 'error') && state?.error !== '') {
context.commit('setError', {
appId: [appId],
error: response.data?.error,
})
}
})
.catch((error) => context.commit('API_FAILURE', error))
},
Expand Down

0 comments on commit 7d3c9ed

Please sign in to comment.