Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
intrn(server): make method to destroy conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Oct 15, 2022
1 parent ad92186 commit 5644e79
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import RequestFilter from "!/bases/request_filter"

export default class AsynchronousOperationInitializer extends RequestFilter {
async filterRequest(request: AsynchronousRequest): Promise<void> {
await request.asynchronousOperation.destroySuccessfully()
await request.asynchronousOperation.destroyConditionally()
}
}
45 changes: 43 additions & 2 deletions server/singletons/asynchronous_operation_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class extends TransactionManager implements AsynchronousOperation

await this.destroySuccessfully()
await this.initialize()
Log.trace("asynchronous", "initialize asynchronous operation")
}

get isNew(): boolean { return !this.hasFound }
Expand Down Expand Up @@ -115,7 +116,19 @@ export default class extends TransactionManager implements AsynchronousOperation
})
}

protected get manager(): BaseManager<any, any, any, any, any, any> {
async destroyConditionally() {
if (this.mayDestroy) {
if (this.isCompletelyFinished) {
await this.destroySuccessfully()
} else {
const reason = "Asynchronous operation did not finished properly"
Log.errorMessage("asynchronous", `${reason} in "${this.origin}"`)
await this.destroyIneffectually()
}
}
}

private get manager(): BaseManager<any, any, any, any, any, any> {
if (this.rawManager === null) {
const developmentPrerequisite = "Asynchronous operation manager should be initialized"
throw new DeveloperError(
Expand All @@ -127,7 +140,7 @@ export default class extends TransactionManager implements AsynchronousOperation
return this.rawManager
}

protected get id(): number {
private get id(): number {
if (this.rawAttributes.id) {
return this.rawAttributes.id
}
Expand All @@ -138,4 +151,32 @@ export default class extends TransactionManager implements AsynchronousOperation
"Developer have executed instructions out of order."
)
}

private get hasStopped(): boolean {
if (this.rawAttributes.hasStopped) {
return this.rawAttributes.hasStopped
}

const developmentPrerequisite = "Asynchronous operation manager should be initialized"
throw new DeveloperError(
`${developmentPrerequisite} before doing something with model manager.`,
"Developer have executed instructions out of order."
)
}

private get origin(): string {
if (this.rawAttributes.origin) {
return this.rawAttributes.origin
}

const developmentPrerequisite = "Asynchronous operation manager should be initialized"
throw new DeveloperError(
`${developmentPrerequisite} before doing something with model manager.`,
"Developer have executed instructions out of order."
)
}

private get isCompletelyFinished(): boolean {
return this.hasStopped && this.finishedStepCount === this.totalStepCount
}
}

0 comments on commit 5644e79

Please sign in to comment.