Skip to content

Commit

Permalink
Merge branch 'feat/78039-135789-delete-unnecessary-page-bulk-export-j…
Browse files Browse the repository at this point in the history
…obs' into feat/78039-151411-cancel-streams-on-export-job-abort
  • Loading branch information
arafubeatbox committed Aug 16, 2024
2 parents 236ea82 + dd5a6e0 commit 07ae16f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ export const PageBulkExportFormat = {

export type PageBulkExportFormat = typeof PageBulkExportFormat[keyof typeof PageBulkExportFormat]

export const PageBulkExportJobStatus = {
export const PageBulkExportJobInProgressStatus = {
initializing: 'initializing', // preparing for export
exporting: 'exporting', // exporting to fs
uploading: 'uploading', // uploading to cloud storage
} as const;

export const PageBulkExportJobStatus = {
...PageBulkExportJobInProgressStatus,
completed: 'completed',
failed: 'failed',
} as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { configManager } from '~/server/service/config-manager';
import CronService from '~/server/service/cron';
import loggerFactory from '~/utils/logger';

import { PageBulkExportJobStatus } from '../../interfaces/page-bulk-export';
import { PageBulkExportJobInProgressStatus, PageBulkExportJobStatus } from '../../interfaces/page-bulk-export';
import type { PageBulkExportJobDocument } from '../models/page-bulk-export-job';
import PageBulkExportJob from '../models/page-bulk-export-job';

Expand Down Expand Up @@ -35,7 +35,7 @@ class PageBulkExportJobCronService extends CronService {
async deleteExpiredExportJobs() {
const exportJobExpirationSeconds = configManager.getConfig('crowi', 'app:bulkExportJobExpirationSeconds');
const expiredExportJobs = await PageBulkExportJob.find({
status: PageBulkExportJobStatus.initializing,
$or: Object.values(PageBulkExportJobInProgressStatus).map(status => ({ status })),
createdAt: { $lt: new Date(Date.now() - exportJobExpirationSeconds * 1000) },
});
for (const expiredExportJob of expiredExportJobs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { preNotifyService } from '~/server/service/pre-notify';
import { getBufferToFixedSizeTransform } from '~/server/util/stream';
import loggerFactory from '~/utils/logger';

import { PageBulkExportFormat, PageBulkExportJobStatus } from '../../interfaces/page-bulk-export';
import { PageBulkExportFormat, PageBulkExportJobInProgressStatus, PageBulkExportJobStatus } from '../../interfaces/page-bulk-export';
import type { PageBulkExportJobDocument } from '../models/page-bulk-export-job';
import PageBulkExportJob from '../models/page-bulk-export-job';
import type { PageBulkExportPageSnapshotDocument } from '../models/page-bulk-export-page-snapshot';
Expand Down Expand Up @@ -126,9 +126,7 @@ class PageBulkExportService {
user: currentUser,
page: basePage,
format,
$or: [
{ status: PageBulkExportJobStatus.initializing }, { status: PageBulkExportJobStatus.exporting }, { status: PageBulkExportJobStatus.uploading },
],
$or: Object.values(PageBulkExportJobInProgressStatus).map(status => ({ status })),
});
if (duplicatePageBulkExportJobInProgress != null) {
throw new DuplicateBulkExportJobError();
Expand Down
6 changes: 2 additions & 4 deletions apps/app/src/server/crowi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import pkg from '^/package.json';

import { KeycloakUserGroupSyncService } from '~/features/external-user-group/server/service/keycloak-user-group-sync';
import { LdapUserGroupSyncService } from '~/features/external-user-group/server/service/ldap-user-group-sync';
import { PageBulkExportJobStatus } from '~/features/page-bulk-export/interfaces/page-bulk-export';
import { PageBulkExportJobInProgressStatus, PageBulkExportJobStatus } from '~/features/page-bulk-export/interfaces/page-bulk-export';
import PageBulkExportJob from '~/features/page-bulk-export/server/models/page-bulk-export-job';
import instanciatePageBulkExportService, { pageBulkExportService } from '~/features/page-bulk-export/server/service/page-bulk-export';
import instanciatePageBulkExportJobCronService, { pageBulkExportJobCronService } from '~/features/page-bulk-export/server/service/page-bulk-export-job-cron';
Expand Down Expand Up @@ -800,9 +800,7 @@ Crowi.prototype.setupExternalUserGroupSyncService = function() {
// TODO: Limit the number of jobs to execute in parallel (https://redmine.weseek.co.jp/issues/143599)
Crowi.prototype.resumeIncompletePageBulkExportJobs = async function() {
const jobs = await PageBulkExportJob.find({
$or: [
{ status: PageBulkExportJobStatus.initializing }, { status: PageBulkExportJobStatus.exporting }, { status: PageBulkExportJobStatus.uploading },
],
$or: Object.values(PageBulkExportJobInProgressStatus).map(status => ({ status })),
});
Promise.all(jobs.map(job => pageBulkExportService.executePageBulkExportJob(job)));
};
Expand Down

0 comments on commit 07ae16f

Please sign in to comment.