mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor: use handleCreateJob
This commit is contained in:
@@ -6,6 +6,7 @@ import type {
|
|||||||
ApiKeyResponseDto,
|
ApiKeyResponseDto,
|
||||||
AssetResponseDto,
|
AssetResponseDto,
|
||||||
IntegrityReportType,
|
IntegrityReportType,
|
||||||
|
JobCreateDto,
|
||||||
LibraryResponseDto,
|
LibraryResponseDto,
|
||||||
LoginResponseDto,
|
LoginResponseDto,
|
||||||
PersonResponseDto,
|
PersonResponseDto,
|
||||||
@@ -68,6 +69,8 @@ export type Events = {
|
|||||||
IntegrityReportDeleteStatus: [{ type?: IntegrityReportType; id?: string; isDeleting: boolean }];
|
IntegrityReportDeleteStatus: [{ type?: IntegrityReportType; id?: string; isDeleting: boolean }];
|
||||||
IntegrityReportDeleted: [{ type?: IntegrityReportType; id?: string }];
|
IntegrityReportDeleted: [{ type?: IntegrityReportType; id?: string }];
|
||||||
|
|
||||||
|
JobCreate: [{ dto: JobCreateDto }];
|
||||||
|
|
||||||
LibraryCreate: [LibraryResponseDto];
|
LibraryCreate: [LibraryResponseDto];
|
||||||
LibraryUpdate: [LibraryResponseDto];
|
LibraryUpdate: [LibraryResponseDto];
|
||||||
LibraryDelete: [{ id: string }];
|
LibraryDelete: [{ id: string }];
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { getFormatter } from '$lib/utils/i18n';
|
import { getFormatter } from '$lib/utils/i18n';
|
||||||
import { createJob, type JobCreateDto } from '@immich/sdk';
|
import { createJob, type JobCreateDto } from '@immich/sdk';
|
||||||
@@ -8,6 +9,7 @@ export const handleCreateJob = async (dto: JobCreateDto) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await createJob({ jobCreateDto: dto });
|
await createJob({ jobCreateDto: dto });
|
||||||
|
eventManager.emit('JobCreate', { dto });
|
||||||
toastManager.success($t('admin.job_created'));
|
toastManager.success($t('admin.job_created'));
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import AdminPageLayout from '$lib/components/layouts/AdminPageLayout.svelte';
|
import AdminPageLayout from '$lib/components/layouts/AdminPageLayout.svelte';
|
||||||
|
import OnEvents from '$lib/components/OnEvents.svelte';
|
||||||
import ServerStatisticsCard from '$lib/components/server-statistics/ServerStatisticsCard.svelte';
|
import ServerStatisticsCard from '$lib/components/server-statistics/ServerStatisticsCard.svelte';
|
||||||
import { AppRoute } from '$lib/constants';
|
import { AppRoute } from '$lib/constants';
|
||||||
|
import { handleCreateJob } from '$lib/services/job.service';
|
||||||
import { getMaintenanceAdminActions } from '$lib/services/maintenance.service';
|
import { getMaintenanceAdminActions } from '$lib/services/maintenance.service';
|
||||||
import { asyncTimeout } from '$lib/utils';
|
import { asyncTimeout } from '$lib/utils';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
|
||||||
import {
|
import {
|
||||||
createJob,
|
|
||||||
getIntegrityReportSummary,
|
getIntegrityReportSummary,
|
||||||
getQueuesLegacy,
|
getQueuesLegacy,
|
||||||
IntegrityReportType,
|
IntegrityReportType,
|
||||||
ManualJobName,
|
ManualJobName,
|
||||||
type IntegrityReportSummaryResponseDto,
|
type IntegrityReportSummaryResponseDto,
|
||||||
|
type JobCreateDto,
|
||||||
type QueuesResponseLegacyDto,
|
type QueuesResponseLegacyDto,
|
||||||
} from '@immich/sdk';
|
} from '@immich/sdk';
|
||||||
import { Button, HStack, toastManager } from '@immich/ui';
|
import { Button, HStack } from '@immich/ui';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import type { PageData } from './$types';
|
import type { PageData } from './$types';
|
||||||
@@ -34,44 +35,21 @@
|
|||||||
IntegrityReportType.ChecksumMismatch,
|
IntegrityReportType.ChecksumMismatch,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const INTEGRITY_JOB_NAMES: Record<IntegrityReportType, ManualJobName> = {
|
||||||
|
[IntegrityReportType.UntrackedFile]: ManualJobName.IntegrityUntrackedFiles,
|
||||||
|
[IntegrityReportType.MissingFile]: ManualJobName.IntegrityMissingFiles,
|
||||||
|
[IntegrityReportType.ChecksumMismatch]: ManualJobName.IntegrityChecksumMismatch,
|
||||||
|
};
|
||||||
|
|
||||||
|
const INTEGRITY_REFRESH_JOB_NAMES: Record<IntegrityReportType, ManualJobName> = {
|
||||||
|
[IntegrityReportType.UntrackedFile]: ManualJobName.IntegrityUntrackedFilesRefresh,
|
||||||
|
[IntegrityReportType.MissingFile]: ManualJobName.IntegrityMissingFilesRefresh,
|
||||||
|
[IntegrityReportType.ChecksumMismatch]: ManualJobName.IntegrityChecksumMismatchRefresh,
|
||||||
|
};
|
||||||
|
|
||||||
let jobs: QueuesResponseLegacyDto | undefined = $state();
|
let jobs: QueuesResponseLegacyDto | undefined = $state();
|
||||||
let expectingUpdate: boolean = $state(false);
|
let expectingUpdate: boolean = $state(false);
|
||||||
|
|
||||||
async function runJob(reportType: IntegrityReportType, refreshOnly?: boolean) {
|
|
||||||
let name: ManualJobName;
|
|
||||||
switch (reportType) {
|
|
||||||
case IntegrityReportType.UntrackedFile: {
|
|
||||||
name = refreshOnly ? ManualJobName.IntegrityUntrackedFilesRefresh : ManualJobName.IntegrityUntrackedFiles;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IntegrityReportType.MissingFile: {
|
|
||||||
name = refreshOnly ? ManualJobName.IntegrityMissingFilesRefresh : ManualJobName.IntegrityMissingFiles;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IntegrityReportType.ChecksumMismatch: {
|
|
||||||
name = refreshOnly ? ManualJobName.IntegrityChecksumMismatchRefresh : ManualJobName.IntegrityChecksumMismatch;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await createJob({ jobCreateDto: { name } });
|
|
||||||
if (jobs) {
|
|
||||||
expectingUpdate = true;
|
|
||||||
jobs.integrityCheck.queueStatus.isActive = true;
|
|
||||||
}
|
|
||||||
toastManager.success($t('admin.job_created'));
|
|
||||||
} catch (error) {
|
|
||||||
handleError(error, $t('errors.unable_to_submit_job'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runAllJobs(refreshOnly?: boolean) {
|
|
||||||
for (const reportType of Object.values(IntegrityReportType)) {
|
|
||||||
await runJob(reportType, refreshOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let running = true;
|
let running = true;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
@@ -91,8 +69,22 @@
|
|||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
running = false;
|
running = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function onJobCreate({ dto }: { dto: JobCreateDto }) {
|
||||||
|
if (
|
||||||
|
Object.values(INTEGRITY_JOB_NAMES).some((name) => name === dto.name) ||
|
||||||
|
Object.values(INTEGRITY_REFRESH_JOB_NAMES).some((name) => name === dto.name)
|
||||||
|
) {
|
||||||
|
if (jobs) {
|
||||||
|
expectingUpdate = true;
|
||||||
|
jobs.integrityCheck.queueStatus.isActive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<OnEvents {onJobCreate} />
|
||||||
|
|
||||||
<AdminPageLayout breadcrumbs={[{ title: data.meta.title }]} actions={[StartMaintenance]}>
|
<AdminPageLayout breadcrumbs={[{ title: data.meta.title }]} actions={[StartMaintenance]}>
|
||||||
<section id="setting-content" class="flex place-content-center sm:mx-4">
|
<section id="setting-content" class="flex place-content-center sm:mx-4">
|
||||||
<section class="w-full pb-28 sm:w-5/6 md:w-[850px]">
|
<section class="w-full pb-28 sm:w-5/6 md:w-[850px]">
|
||||||
@@ -101,14 +93,14 @@
|
|||||||
<Button
|
<Button
|
||||||
size="tiny"
|
size="tiny"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onclick={() => runAllJobs()}
|
onclick={() => Object.values(INTEGRITY_JOB_NAMES).forEach((name) => handleCreateJob({ name }))}
|
||||||
class="self-end mt-1"
|
class="self-end mt-1"
|
||||||
disabled={jobs?.integrityCheck.queueStatus.isActive}>{$t('admin.maintenance_integrity_check_all')}</Button
|
disabled={jobs?.integrityCheck.queueStatus.isActive}>{$t('admin.maintenance_integrity_check_all')}</Button
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
size="tiny"
|
size="tiny"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onclick={() => runAllJobs(true)}
|
onclick={() => Object.values(INTEGRITY_REFRESH_JOB_NAMES).forEach((name) => handleCreateJob({ name }))}
|
||||||
class="self-end mt-1"
|
class="self-end mt-1"
|
||||||
disabled={jobs?.integrityCheck.queueStatus.isActive}>{$t('refresh')}</Button
|
disabled={jobs?.integrityCheck.queueStatus.isActive}>{$t('refresh')}</Button
|
||||||
></HStack
|
></HStack
|
||||||
@@ -123,7 +115,10 @@
|
|||||||
{#snippet footer()}
|
{#snippet footer()}
|
||||||
<HStack gap={1} class="justify-end">
|
<HStack gap={1} class="justify-end">
|
||||||
<Button
|
<Button
|
||||||
onclick={() => runJob(reportType)}
|
onclick={() =>
|
||||||
|
handleCreateJob({
|
||||||
|
name: INTEGRITY_JOB_NAMES[reportType],
|
||||||
|
})}
|
||||||
size="tiny"
|
size="tiny"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
class="self-end mt-1"
|
class="self-end mt-1"
|
||||||
@@ -131,7 +126,10 @@
|
|||||||
>{$t('admin.maintenance_integrity_check_all')}</Button
|
>{$t('admin.maintenance_integrity_check_all')}</Button
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
onclick={() => runJob(reportType, true)}
|
onclick={() =>
|
||||||
|
handleCreateJob({
|
||||||
|
name: INTEGRITY_REFRESH_JOB_NAMES[reportType],
|
||||||
|
})}
|
||||||
size="tiny"
|
size="tiny"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
class="self-end mt-1"
|
class="self-end mt-1"
|
||||||
|
|||||||
Reference in New Issue
Block a user