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

fix(server): fix tasks state handler logic #987

Merged
merged 1 commit into from
Mar 30, 2023
Merged

Conversation

maslow
Copy link
Member

@maslow maslow commented Mar 30, 2023

No description provided.

@maslow maslow merged commit d36eab9 into labring:main Mar 30, 2023
{ lockedAt: { $lt: new Date(Date.now() - 1000 * this.lockTimeout) } },
{ $set: { lockedAt: TASK_LOCK_INIT_TIME } },
)
}
}
Copy link

Choose a reason for hiding this comment

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

!

Code Review:

  1. In the handleDeletedState method, the clearTimeoutLocks method is removed which I think is not necessary.
  2. In the handleCreatedState method, if (!res.value) return is added which looks good.
  3. In the handleDeletedState method, if (updated.modifiedCount > 0) this.logger.debug('app phase updated to Deleted:', app.appid) is replaced with this.logger.log('app phase updated to Deleted: ' + app.appid). This is good as it is more easier to understand.
  4. In the clearDeletedApps method, the TODO comment should be removed and the state should be set to ApplicationState.Deleted.
  5. In the unlockApplication method, the lockedAt variable should be set to TASK_LOCK_INIT_TIME instead of 0.
  6. In the clearTimeoutLocks method, the lockedAt variable should be set to TASK_LOCK_INIT_TIME instead of 0.

Hope this helps.

@@ -283,6 +285,7 @@ export class WebsiteTaskService {
{
state: DomainState.Deleted,
phase: DomainPhase.Created,
lockedAt: { $lt: new Date(Date.now() - 1000 * this.lockTimeout) },
},
{
$set: {
Copy link

Choose a reason for hiding this comment

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

with the code review

The patch looks good and there is no bug risk. The updateMany() method has been updated to include two new conditions: $in, which checks for multiple values; and $lt, which checks for a lockedAt value that is less than a certain time interval. Both of these conditions should help improve the accuracy and performance of the query. Additionally, the lockTimeout variable has been added in order to set a reasonable timeout limit for the query.

@maslow maslow deleted the opt-tasks branch March 30, 2023 19:17
if (!namespace) {
return
}
if (!namespace) return

const appsV1Api = this.clusterService.makeAppsV1Api(region)
const coreV1Api = this.clusterService.makeCoreV1Api(region)
Copy link

Choose a reason for hiding this comment

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

off with a code review!

First, we can see that the original code was trying to check for a namespace before continuing. However, the updated code simply returns if there is no namespace, so it appears the condition will be more efficiently handled.

We can also note that the code is making use of the ClusterService class to make an appsV1Api and coreV1Api which implies that those objects are needed for further processing. It would be worth verifying this is the case to ensure the intended functionality is preserved.

Finally, there are no obvious bugs in the code. However, it would be worth considering if there is any additional error handling that should be included in case something unexpected occurs.

state: DomainState.Deleted,
phase: { $in: [DomainPhase.Created, DomainPhase.Creating] },
lockedAt: { $lt: new Date(Date.now() - 1000 * this.lockTimeout) },
},
{
$set: { phase: DomainPhase.Deleting, lockedAt: TASK_LOCK_INIT_TIME },
},
Copy link

Choose a reason for hiding this comment

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

with code review

First, the code patch is intended to update the document in the 'StorageBucket' collection in the SystemDatabase with conditions based on the state and phase of the domain.

The code patch adds a condition - lockedAt - to the query used to locate the documents that need to be updated. The condition checks if the lockedAt of the document is less than the current date minus 1000 times the value of lockTimeout. This condition ensures that only documents that have been locked for longer than the timeout are selected for update.

Another thing to note is that the value of the 'phase' field is being set to different values depending on the initial state and phase of the document. This ensures that the document is updated to the correct state.

Overall, the code patch looks correct and should work as expected. However, it is recommended to add tests to ensure that the code is doing what it is supposed to do.

{
state: TriggerState.Inactive,
phase: { $in: [TriggerPhase.Created, TriggerPhase.Creating] },
},
{
$set: { phase: TriggerPhase.Deleting, lockedAt: TASK_LOCK_INIT_TIME },
},
Copy link

Choose a reason for hiding this comment

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

with code review:

1.It looks like the code is attempting to update the state of a CronTrigger to Inactive, when it is in either the Created or Creating phase.
2.The code is also setting the lockedAt field to the TASK_LOCK_INIT_TIME.
3.It appears that the code is properly using the SystemDataBase to update the data and is not using any deprecated functions.
4.The code should be tested to ensure that it is working as expected.
5.It looks like the code is missing an 'import assert from 'node:assert' statement. This should be added in order for the code to work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant