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 facility sync elapsed time #12158

Conversation

AlexVelezLl
Copy link
Member

Summary

Refresh elapsed time since last sync in the Facility sync status

References

Closes #10759

Reviewer guidance

Reproduce #10759

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@pcenov
Copy link
Member

pcenov commented May 13, 2024

Hi @AlexVelezLl, the fix is working correctly at Device > Facilities if I click the Sync button and select to sync either to KDP or a facility in the local network. However if while I am at Device > Facilities I go to Options > Manage sync schedule and I edit the sync schedule, when I go back to Device > Facilities then I see that there's a sync in progress and after it has finished the Last synced value doesn't refresh automatically:

2024-05-13_12-25-07.mp4

Also, we have the same sync feature at Facility > Data where I am not seeing the auto refresh at all:

data.mp4

@github-actions github-actions bot added APP: Device Re: Device App (content import/export, facility-syncing, user permissions, etc.) APP: Facility Re: Facility App (user/class management, facility settings, csv import/export, etc.) labels May 13, 2024
for (const index in newTasks) {
const task = newTasks[index];
if (this.taskIdsToWatch.includes(task.id)) {
if (task.status === TaskStatuses.COMPLETED) {
if (
task.status === TaskStatuses.COMPLETED ||
Copy link
Member Author

Choose a reason for hiding this comment

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

We werent taking into account that repeating tasks doesnt have a "completed" status when they are synced and thats why we hadnt the last_successful_sync value updated.

@AlexVelezLl
Copy link
Member Author

Thank you @pcenov! I have addressed the issue in both places.

Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

A couple of questions about the code.

return false;
}
const prevTask = prevTasks.find(({ id }) => id === task.id);
if (!prevTask) {
Copy link
Member

Choose a reason for hiding this comment

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

Hrm, wondering why there is this "previous task" at all, the API should only be returning a single job status from the backend for an id.

If it is happening, liable to be a frontend state persisting which would go away if we refreshed the page.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably, the name should be improved. Here, by previousTasks, I mean the previous snapshot of the tasks list. The thing is that for repeating tasks, we never had the task with a "COMPLETED" status, and thereby this line is not executed, and we do not have the updated value of facility.last_successful_sync .

The problem is that repeating tasks keep the same reference for multiple executions, and they never end in a "COMPLETED" status because, after the "RUNNING" state, they pass to "QUEUED" again when the execution ends. So the way I found to determine if a single task run has been completed was comparing the current state of the task with the previous snapshot.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah - my point was that if this is working it's because we had data from a previous fetch where the task was in progress, so it's quite possible that on a refresh of the page we would still get an issue here.

I don't think this needs to be resolved now - but there's definitely some cleanup we can do overall for how we handle tasks on the frontend (probably through a core useTasks composable that consolidates a lot of this logic).

TaskResource.clear(this.syncTaskId);
this.syncTaskId = '';
Copy link
Member

Choose a reason for hiding this comment

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

Why did this need to be moved? The clear method returns a promise, so if we want to wait until after the clear we would need to await it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh no no, I am not sure the reason for setting an empty string to syncTaskId, but the thing was that if we first set this.syncTaskId = ''; and after we execute TaskResource.clear(this.syncTaskId);, we would be excecuting TaskResource.clear with an empty string, and because of this, it was throwing an exception, and the code below wasn't executing, and therefore the last sync value wasn't being updated.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that makes a lot of sense, yes!

@pcenov
Copy link
Member

pcenov commented May 14, 2024

Hi @AlexVelezLl I confirm that the reported issues are fixed now and there are no new issues observed while manually testing. LGTM!

Copy link
Member

@radinamatic radinamatic left a comment

Choose a reason for hiding this comment

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

Manual QA passes, good to go! 💯 👏🏽 :shipit:

@rtibbles rtibbles merged commit 16cbcae into learningequality:release-v0.16.x May 14, 2024
34 checks passed
@AlexVelezLl AlexVelezLl deleted the fix-facility-sync-elapsedtime branch May 14, 2024 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Device Re: Device App (content import/export, facility-syncing, user permissions, etc.) APP: Facility Re: Facility App (user/class management, facility settings, csv import/export, etc.) DEV: frontend SIZE: small TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants