Skip to content

Commit

Permalink
Merge pull request #12158 from AlexVelezLl/fix-facility-sync-elapsedtime
Browse files Browse the repository at this point in the history
Fix facility sync elapsed time
  • Loading branch information
rtibbles authored May 14, 2024
2 parents 405b30a + 06546c6 commit 16cbcae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@

<script>
import { now } from 'kolibri.utils.serverClock';
import useNow from 'kolibri.coreVue.composables.useNow';
import taskStrings from 'kolibri.coreVue.mixins.commonTaskStrings';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
export default {
name: 'FacilityNameAndSyncStatus',
mixins: [taskStrings, commonCoreStrings],
setup() {
const { now } = useNow();
return { now };
},
props: {
facility: {
type: Object,
Expand All @@ -105,11 +109,6 @@
required: true,
},
},
data() {
return {
now: now(),
};
},
computed: {
syncFailed() {
const lastSyncFailed =
Expand Down
17 changes: 15 additions & 2 deletions kolibri/plugins/device/assets/src/views/FacilitiesPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,14 @@
},
watch: {
// Update facilities whenever a watched task completes
facilityTasks(newTasks) {
facilityTasks(newTasks, prevTasks) {
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 ||
this.isRepeatingTaskCompleted(task, prevTasks)
) {
this.fetchFacilites();
if (task.type === TaskTypes.DELETEFACILITY) {
this.showFacilityRemovedSnackbar(task.facility_name);
Expand All @@ -284,6 +287,16 @@
.catch(() => (this.loadingFacilities = false));
},
methods: {
isRepeatingTaskCompleted(task, prevTasks) {
if (!task.repeat_interval) {
return false;
}
const prevTask = prevTasks.find(({ id }) => id === task.id);
if (!prevTask) {
return false;
}
return prevTask.status === TaskStatuses.RUNNING && task.status === TaskStatuses.QUEUED;
},
facilityOptions() {
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@
TaskResource.get(this.syncTaskId).then(task => {
if (task.clearable) {
this.isSyncing = false;
this.syncTaskId = '';
TaskResource.clear(this.syncTaskId);
this.syncTaskId = '';
if (task.status === TaskStatuses.FAILED) {
this.syncHasFailed = true;
} else if (task.status === TaskStatuses.COMPLETED) {
Expand Down

0 comments on commit 16cbcae

Please sign in to comment.