Skip to content

Commit 03d1c31

Browse files
committed
refactor updateTask function, update vue-libraries, and improve wording
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent 16aa437 commit 03d1c31

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@nextcloud/l10n": "^3.1.0",
5050
"@nextcloud/moment": "^1.3.1",
5151
"@nextcloud/router": "^3.0.0",
52-
"@nextcloud/vue": "^9.0.0-rc.2",
52+
"@nextcloud/vue": "^9.0.0-rc.4",
5353
"extendable-media-recorder": "^9.2.11",
5454
"extendable-media-recorder-wav-encoder": "^7.0.129",
5555
"moment": "^2.30.1",

src/assistant.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export async function openAssistantForm({
137137
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
138138
showError(
139139
t('assistant', 'The server failed to process your task with ID {id}', { id: finishedTask.id })
140-
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
140+
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
141141
)
142142
console.error('[assistant] Task failed', finishedTask)
143143
view.outputs = null
@@ -212,7 +212,7 @@ export async function openAssistantForm({
212212
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
213213
showError(
214214
t('assistant', 'The server failed to process your task with ID {id}', { id: finishedTask.id })
215-
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
215+
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
216216
)
217217
console.error('[assistant] Task failed', finishedTask)
218218
view.outputs = null
@@ -272,7 +272,7 @@ function updateTask(task, object) {
272272
object.scheduledAt = task?.scheduledAt
273273
}
274274

275-
export async function pollTask(taskId, obj) {
275+
export async function pollTask(taskId, obj, callback = updateTask) {
276276
return new Promise((resolve, reject) => {
277277
window.assistantPollTimerId = setInterval(() => {
278278
getTask(taskId).then(response => {
@@ -282,7 +282,7 @@ export async function pollTask(taskId, obj) {
282282
return
283283
}
284284
if (obj) {
285-
updateTask(task, obj)
285+
callback(task, obj)
286286
}
287287
if (![TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(task?.status)) {
288288
// stop polling
@@ -528,7 +528,7 @@ export async function openAssistantTask(
528528
lastTask = task
529529
view.selectedTaskId = lastTask?.id
530530
view.expectedRuntime = (lastTask?.completionExpectedAt - lastTask?.scheduledAt) || null
531-
pollTask(task.id).then(finishedTask => {
531+
pollTask(task.id, view).then(finishedTask => {
532532
if (finishedTask.status === TASK_STATUS_STRING.successful) {
533533
view.outputs = finishedTask?.output
534534
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {

src/components/RunningEmptyContent.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
{{ t('assistant', 'Cancel task') }}
3434
</NcButton>
3535
<NcNoteCard v-if="taskStatus === TASK_STATUS_STRING.scheduled && toLongForScheduling" show-alert type="warning">
36-
{{ t('assistant', 'This task is taking longer to start running than expected. Please contact your administrator to ensure this task type is being picked up.') }}
36+
{{ t('assistant', 'This task is taking longer to start running than expected. Please contact your administrator to ensure that this is correctly configured.') }}
3737
</NcNoteCard>
3838
</div>
3939
</template>
@@ -103,12 +103,15 @@ export default {
103103
104104
data() {
105105
return {
106-
toLongForScheduling: false,
106+
now: Date.now() / 1000,
107107
timer: null,
108108
}
109109
},
110110
111111
computed: {
112+
toLongForScheduling() {
113+
return this.scheduledAt !== null && this.scheduledAt + 60 * 5 < this.now
114+
},
112115
TASK_STATUS_STRING() {
113116
return TASK_STATUS_STRING
114117
},
@@ -131,11 +134,9 @@ export default {
131134
132135
mounted() {
133136
this.timer = setInterval(() => {
134-
if (this.scheduledAt === null) {
135-
this.toLongForScheduling = false
136-
return
137-
}
138-
this.toLongForScheduling = this.scheduledAt + 60 * 5 < Date.now() / 1000
137+
console.debug('scheduledAt', this.scheduledAt)
138+
console.debug('status', this.taskStatus)
139+
this.now = Date.now() / 1000
139140
}, 2000)
140141
},
141142

src/views/AssistantPage.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
:loading="loading"
1616
:show-sync-task-running="showSyncTaskRunning"
1717
:short-input="shortInput"
18-
:task-status="taskStatus"
19-
:scheduled-at="scheduledAt"
18+
:task-status="task.status"
19+
:scheduled-at="task.scheduledAt"
2020
:progress="progress"
2121
:expected-runtime="expectedRuntime"
2222
:is-notify-enabled="isNotifyEnabled"
@@ -69,8 +69,6 @@ export default {
6969
progress: null,
7070
loading: false,
7171
isNotifyEnabled: false,
72-
taskStatus: null,
73-
scheduledAt: null,
7472
}
7573
},
7674
@@ -126,7 +124,7 @@ export default {
126124
this.task.id = task.id
127125
this.task.completionExpectedAt = task.completionExpectedAt
128126
this.task.scheduledAt = task.scheduledAt
129-
pollTask(task.id, this).then(finishedTask => {
127+
pollTask(task.id, this, this.updateTask).then(finishedTask => {
130128
if (finishedTask.status === TASK_STATUS_STRING.successful) {
131129
this.task.output = finishedTask?.output
132130
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
@@ -148,6 +146,12 @@ export default {
148146
.then(() => {
149147
})
150148
},
149+
updateTask(task) {
150+
if (task.status === TASK_STATUS_STRING.running) {
151+
this.progress = task.progress
152+
}
153+
this.task = task
154+
},
151155
onSyncSubmit(data) {
152156
this.syncSubmit(data.inputs, data.selectedTaskTypeId, this.task.identifier)
153157
},

0 commit comments

Comments
 (0)