chore(server) Add job for storage migration (#1117)

This commit is contained in:
Alex
2022-12-19 12:13:10 -06:00
committed by GitHub
parent 8998a79ff9
commit de69d0031e
33 changed files with 398 additions and 241 deletions

View File

@@ -225,6 +225,12 @@ export interface AllJobStatusResponseDto {
* @memberof AllJobStatusResponseDto
*/
'machineLearningQueueCount': JobCounts;
/**
*
* @type {JobCounts}
* @memberof AllJobStatusResponseDto
*/
'storageMigrationQueueCount': JobCounts;
/**
*
* @type {boolean}
@@ -249,6 +255,12 @@ export interface AllJobStatusResponseDto {
* @memberof AllJobStatusResponseDto
*/
'isMachineLearningActive': boolean;
/**
*
* @type {boolean}
* @memberof AllJobStatusResponseDto
*/
'isStorageMigrationActive': boolean;
}
/**
*
@@ -1038,7 +1050,8 @@ export const JobId = {
ThumbnailGeneration: 'thumbnail-generation',
MetadataExtraction: 'metadata-extraction',
VideoConversion: 'video-conversion',
MachineLearning: 'machine-learning'
MachineLearning: 'machine-learning',
StorageTemplateMigration: 'storage-template-migration'
} as const;
export type JobId = typeof JobId[keyof typeof JobId];

View File

@@ -9,6 +9,7 @@
let allJobsStatus: AllJobStatusResponseDto;
let setIntervalHandler: NodeJS.Timer;
onMount(async () => {
const { data } = await api.jobApi.getAllJobsStatus();
allJobsStatus = data;
@@ -104,6 +105,33 @@
});
}
};
const runTemplateMigration = async () => {
try {
const { data } = await api.jobApi.sendJobCommand(JobId.StorageTemplateMigration, {
command: JobCommand.Start
});
if (data) {
notificationController.show({
message: `Storage migration started`,
type: NotificationType.Info
});
} else {
notificationController.show({
message: `All files have been migrated to the new storage template`,
type: NotificationType.Info
});
}
} catch (e) {
console.log('[ERROR] runTemplateMigration', e);
notificationController.show({
message: `Error running template migration job, check console for more detail`,
type: NotificationType.Error
});
}
};
</script>
<div class="flex flex-col gap-10">
@@ -135,4 +163,20 @@
>
Note that some asset does not have any object detected, this is normal.
</JobTile>
<JobTile
title={'Storage migration'}
subtitle={''}
on:click={runTemplateMigration}
jobStatus={allJobsStatus?.isStorageMigrationActive}
waitingJobCount={allJobsStatus?.storageMigrationQueueCount.waiting}
activeJobCount={allJobsStatus?.storageMigrationQueueCount.active}
>
Apply the current
<a
href="/admin/system-settings?open=storage-template"
class="text-immich-primary dark:text-immich-dark-primary">Storage template</a
>
to previously uploaded assets
</JobTile>
</div>

View File

@@ -3,7 +3,7 @@
export let title: string;
export let subtitle = '';
let isOpen = false;
export let isOpen = false;
const toggle = () => (isOpen = !isOpen);
</script>

View File

@@ -214,6 +214,16 @@
</div>
</div>
<div id="migration-info" class="text-sm mt-4">
<p>
Template changes will only apply to new assets. To retroactively apply the template to
previously uploaded assets, run the <a
href="/admin/jobs-status"
class="text-immich-primary dark:text-immich-dark-primary">Storage Migration Job</a
>
</p>
</div>
<SettingButtonsRow
on:reset={reset}
on:save={saveSetting}

View File

@@ -73,7 +73,7 @@
</div>
<section id="setting-content" class="pt-[85px] flex place-content-center">
<section class="w-[800px] pt-5">
<section class="w-[800px] pt-5 pb-28">
<slot />
</section>
</section>

View File

@@ -6,6 +6,7 @@
import LoadingSpinner from '$lib/components/shared-components/loading-spinner.svelte';
import { api, SystemConfigDto } from '@api';
import type { PageData } from './$types';
import { page } from '$app/stores';
let systemConfig: SystemConfigDto;
export let data: PageData;
@@ -39,6 +40,7 @@
<SettingAccordion
title="Storage Template"
subtitle="Manage the folder structure and file name of the upload asset"
isOpen={$page.url.searchParams.get('open') === 'storage-template'}
>
<StorageTemplateSettings storageConfig={configs.storageTemplate} user={data.user} />
</SettingAccordion>