Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.
TypeScript
fix(Kiwix): avoid restarting container while download jobs running
Jake Turner5e584eb5d0bf
diff --git a/admin/app/services/zim_service.ts b/admin/app/services/zim_service.tsindex 870cb958..2b1ac610 100644--- a/admin/app/services/zim_service.ts+++ b/admin/app/services/zim_service.ts@@ -275,13 +275,40 @@ export class ZimService implements IZimService {}}- // Restart KIWIX container to pick up new ZIM fileif (restart) {- await this.dockerService- .affectContainer(SERVICE_NAMES.KIWIX, 'restart')- .catch((error) => {- logger.error(`[ZimService] Failed to restart KIWIX container:`, error) // Don't stop the download completion, just log the error.- })+ // Check if there are any remaining ZIM download jobs before restarting+ const { QueueService } = await import('./queue_service.js')+ const queueService = new QueueService()+ const queue = queueService.getQueue('downloads')++ // Get all active and waiting jobs+ const [activeJobs, waitingJobs] = await Promise.all([+ queue.getActive(),+ queue.getWaiting(),+ ])++ // Filter out completed jobs (progress === 100) to avoid race condition+ // where this job itself is still in the active queue+ const activeIncompleteJobs = activeJobs.filter((job) => {+ const progress = typeof job.progress === 'number' ? job.progress : 0+ return progress < 100+ })++ // Check if any remaining incomplete jobs are ZIM downloads+ const allJobs = [...activeIncompleteJobs, ...waitingJobs]+ const hasRemainingZimJobs = allJobs.some((job) => job.data.filetype === 'zim')++ if (hasRemainingZimJobs) {+ logger.info('[ZimService] Skipping container restart - more ZIM downloads pending')+ } else {+ // Restart KIWIX container to pick up new ZIM file+ logger.info('[ZimService] No more ZIM downloads pending - restarting KIWIX container')+ await this.dockerService+ .affectContainer(SERVICE_NAMES.KIWIX, 'restart')+ .catch((error) => {+ logger.error(`[ZimService] Failed to restart KIWIX container:`, error) // Don't stop the download completion, just log the error.+ })+ }}// Mark any curated collection resources with this download URL as downloadeddiff --git a/admin/inertia/pages/easy-setup/complete.tsx b/admin/inertia/pages/easy-setup/complete.tsxindex 56e97c7b..d8830b57 100644--- a/admin/inertia/pages/easy-setup/complete.tsx+++ b/admin/inertia/pages/easy-setup/complete.tsx@@ -34,7 +34,7 @@ export default function EasySetupWizardComplete() {<ActiveDownloads withHeader /><Alerttitle="Running in the Background"- message='Feel free to leave this page at any time - your app installs and downloads will continue in the background!'+ 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.'type="info"variant="solid"className='mt-12'