mirror of
https://github.com/labring/laf.git
synced 2026-02-01 16:57:03 +00:00
fix(server): cannot restart stopped app (#1129)
This commit is contained in:
parent
de080a888b
commit
5477994ea1
@ -18,7 +18,11 @@ import { ApplicationService } from './application.service'
|
||||
import { FunctionService } from '../function/function.service'
|
||||
import { StorageService } from 'src/storage/storage.service'
|
||||
import { RegionService } from 'src/region/region.service'
|
||||
import { SubscriptionPhase } from '@prisma/client'
|
||||
import {
|
||||
ApplicationPhase,
|
||||
ApplicationState,
|
||||
SubscriptionPhase,
|
||||
} from '@prisma/client'
|
||||
|
||||
@ApiTags('Application')
|
||||
@Controller('applications')
|
||||
@ -139,6 +143,39 @@ export class ApplicationController {
|
||||
return ResponseUtil.error('subscription has expired, you can not update')
|
||||
}
|
||||
|
||||
// check: only running application can restart
|
||||
if (
|
||||
dto.state === ApplicationState.Restarting &&
|
||||
app.state !== ApplicationState.Running &&
|
||||
app.phase !== ApplicationPhase.Started
|
||||
) {
|
||||
return ResponseUtil.error(
|
||||
'The application is not running, can not restart it',
|
||||
)
|
||||
}
|
||||
|
||||
// check: only running application can stop
|
||||
if (
|
||||
dto.state === ApplicationState.Stopped &&
|
||||
app.state !== ApplicationState.Running &&
|
||||
app.phase !== ApplicationPhase.Started
|
||||
) {
|
||||
return ResponseUtil.error(
|
||||
'The application is not running, can not stop it',
|
||||
)
|
||||
}
|
||||
|
||||
// check: only stopped application can start
|
||||
if (
|
||||
dto.state === ApplicationState.Running &&
|
||||
app.state !== ApplicationState.Stopped &&
|
||||
app.phase !== ApplicationPhase.Stopped
|
||||
) {
|
||||
return ResponseUtil.error(
|
||||
'The application is not stopped, can not start it',
|
||||
)
|
||||
}
|
||||
|
||||
// update app
|
||||
const res = await this.appService.update(appid, dto)
|
||||
if (res === null) {
|
||||
|
||||
@ -26,7 +26,7 @@ export class InstanceService {
|
||||
private readonly storageService: StorageService,
|
||||
private readonly databaseService: DatabaseService,
|
||||
private readonly prisma: PrismaService,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
async create(app: Application) {
|
||||
const appid = app.appid
|
||||
@ -176,18 +176,23 @@ export class InstanceService {
|
||||
},
|
||||
})
|
||||
const { deployment } = await this.get(app)
|
||||
deployment.spec = await this.makeDeploymentSpec(app, deployment.spec.template.metadata.labels)
|
||||
deployment.spec = await this.makeDeploymentSpec(
|
||||
app,
|
||||
deployment.spec.template.metadata.labels,
|
||||
)
|
||||
const region = await this.regionService.findByAppId(app.appid)
|
||||
const appsV1Api = this.clusterService.makeAppsV1Api(region)
|
||||
const namespace = GetApplicationNamespaceByAppId(app.appid)
|
||||
const res = await appsV1Api.replaceNamespacedDeployment(app.appid, namespace, deployment)
|
||||
const res = await appsV1Api.replaceNamespacedDeployment(
|
||||
app.appid,
|
||||
namespace,
|
||||
deployment,
|
||||
)
|
||||
|
||||
this.logger.log(`restart k8s deployment ${res.body?.metadata?.name}`)
|
||||
|
||||
}
|
||||
|
||||
async makeDeploymentSpec(app: any, labels: any): Promise<V1DeploymentSpec> {
|
||||
|
||||
// prepare params
|
||||
const limitMemory = app.bundle.resource.limitMemory
|
||||
const limitCpu = app.bundle.resource.limitCPU
|
||||
@ -227,8 +232,9 @@ export class InstanceService {
|
||||
},
|
||||
{ name: 'DEPENDENCIES', value: dependencies_string },
|
||||
{
|
||||
name: 'RESTART_AT', value: new Date().getTime().toString(),
|
||||
}
|
||||
name: 'RESTART_AT',
|
||||
value: new Date().getTime().toString(),
|
||||
},
|
||||
]
|
||||
|
||||
// merge env from app configuration, override if exists
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user