Skip to content

Commit 5e584eb

Browse files
committed
fix(Kiwix): avoid restarting container while download jobs running
1 parent cc61fbe commit 5e584eb

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

admin/app/services/zim_service.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,40 @@ export class ZimService implements IZimService {
275275
}
276276
}
277277

278-
// Restart KIWIX container to pick up new ZIM file
279278
if (restart) {
280-
await this.dockerService
281-
.affectContainer(SERVICE_NAMES.KIWIX, 'restart')
282-
.catch((error) => {
283-
logger.error(`[ZimService] Failed to restart KIWIX container:`, error) // Don't stop the download completion, just log the error.
284-
})
279+
// Check if there are any remaining ZIM download jobs before restarting
280+
const { QueueService } = await import('./queue_service.js')
281+
const queueService = new QueueService()
282+
const queue = queueService.getQueue('downloads')
283+
284+
// Get all active and waiting jobs
285+
const [activeJobs, waitingJobs] = await Promise.all([
286+
queue.getActive(),
287+
queue.getWaiting(),
288+
])
289+
290+
// Filter out completed jobs (progress === 100) to avoid race condition
291+
// where this job itself is still in the active queue
292+
const activeIncompleteJobs = activeJobs.filter((job) => {
293+
const progress = typeof job.progress === 'number' ? job.progress : 0
294+
return progress < 100
295+
})
296+
297+
// Check if any remaining incomplete jobs are ZIM downloads
298+
const allJobs = [...activeIncompleteJobs, ...waitingJobs]
299+
const hasRemainingZimJobs = allJobs.some((job) => job.data.filetype === 'zim')
300+
301+
if (hasRemainingZimJobs) {
302+
logger.info('[ZimService] Skipping container restart - more ZIM downloads pending')
303+
} else {
304+
// Restart KIWIX container to pick up new ZIM file
305+
logger.info('[ZimService] No more ZIM downloads pending - restarting KIWIX container')
306+
await this.dockerService
307+
.affectContainer(SERVICE_NAMES.KIWIX, 'restart')
308+
.catch((error) => {
309+
logger.error(`[ZimService] Failed to restart KIWIX container:`, error) // Don't stop the download completion, just log the error.
310+
})
311+
}
285312
}
286313

287314
// Mark any curated collection resources with this download URL as downloaded

admin/inertia/pages/easy-setup/complete.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function EasySetupWizardComplete() {
3434
<ActiveDownloads withHeader />
3535
<Alert
3636
title="Running in the Background"
37-
message='Feel free to leave this page at any time - your app installs and downloads will continue in the background!'
37+
message='Feel free to leave this page at any time - your app installs and downloads will continue in the background! Please note, the Information Library (if installed) may be unavailable until all initial downloads complete.'
3838
type="info"
3939
variant="solid"
4040
className='mt-12'

0 commit comments

Comments
 (0)