feat(category): 类目树、属性、属性字典维护,新增系统管理员管理类目数据
This commit is contained in:
+36
-6
@@ -19,17 +19,25 @@ import {
|
||||
type CatalogSyncScope,
|
||||
} from './ozon-catalog-sync.js';
|
||||
import { scheduleStoreCategoryTreeSync } from './store-category-tree-scheduler.js';
|
||||
import { PlatformCatalogDispatcher, type PlatformCatalogJob } from './platform-catalog-dispatcher.js';
|
||||
import { PlatformCatalogScheduler } from './platform-catalog-scheduler.js';
|
||||
import { markPlatformCatalogUnavailable, syncPlatformCatalog } from './platform-catalog-sync.js';
|
||||
|
||||
const connection = new Redis(workerConfig.redisUrl, {
|
||||
maxRetriesPerRequest: null,
|
||||
});
|
||||
const database = createApplicationDatabase(workerConfig.databaseUrl);
|
||||
const queue = new Queue<OutboxJob>('atlas-dispatch', { connection });
|
||||
const platformQueue = new Queue<PlatformCatalogJob>('atlas-dispatch', { connection });
|
||||
const dispatcher = new OutboxDispatcher(
|
||||
database,
|
||||
queue,
|
||||
`worker_${randomUUID()}`,
|
||||
);
|
||||
const platformDispatcher = new PlatformCatalogDispatcher(
|
||||
database, platformQueue, `platform_worker_${randomUUID()}`,
|
||||
);
|
||||
const platformScheduler = new PlatformCatalogScheduler(database);
|
||||
const objectStorage = new S3Client({
|
||||
endpoint: workerConfig.objectStorageEndpoint,
|
||||
region: 'us-east-1',
|
||||
@@ -54,15 +62,17 @@ type CatalogSyncJob = OutboxJob & {
|
||||
};
|
||||
};
|
||||
|
||||
const worker = new Worker<OutboxJob>(
|
||||
const worker = new Worker<OutboxJob | PlatformCatalogJob>(
|
||||
'atlas-dispatch',
|
||||
async (job) => {
|
||||
if (job.name === 'store_credential_verification.requested') {
|
||||
if (job.name === 'platform_catalog_sync.requested') {
|
||||
await syncPlatformCatalog(database, job.data as PlatformCatalogJob);
|
||||
} else if (job.name === 'store_credential_verification.requested') {
|
||||
await verifyStoreCredentials(database, job.data as OutboxJob & { payload: { store_id: string; operation_id: string; secret_id?: string } });
|
||||
} else if (job.name === 'collection.cleanup.requested') {
|
||||
await cleanupCollection(database, job.data as OutboxJob & { payload: { operation_id: string; collection_item_ids: string[] } });
|
||||
} else if (job.name === 'collection.assets.materialize.requested' || job.name === 'collection.assets.retry.requested') {
|
||||
await materializeCollectionAssets(database, objectStorage, workerConfig.objectStorageBucket, job.data);
|
||||
await materializeCollectionAssets(database, objectStorage, workerConfig.objectStorageBucket, job.data as OutboxJob);
|
||||
} else if (
|
||||
job.name === 'store_category_tree_sync.requested' ||
|
||||
job.name === 'store_category_attribute_sync.requested' ||
|
||||
@@ -84,7 +94,9 @@ async function cleanupCollection(database: Database, job: OutboxJob & { payload:
|
||||
|
||||
worker.on('failed', (job, error) => {
|
||||
if (!job || job.attemptsMade < (job.opts.attempts ?? 1)) return;
|
||||
if (job.name === 'store_credential_verification.requested') {
|
||||
if (job.name === 'platform_catalog_sync.requested') {
|
||||
void markPlatformCatalogUnavailable(database, job.data as PlatformCatalogJob);
|
||||
} else if (job.name === 'store_credential_verification.requested') {
|
||||
void markUnavailable(database, job.data as StoreVerificationJob, error);
|
||||
} else if (
|
||||
job.name === 'store_category_tree_sync.requested' ||
|
||||
@@ -285,20 +297,36 @@ async function markUnavailable(
|
||||
|
||||
let dispatcherTimer: ReturnType<typeof setInterval> | undefined;
|
||||
let mediaCleanupTimer: ReturnType<typeof setInterval> | undefined;
|
||||
let platformCatalogTimer: ReturnType<typeof setInterval> | undefined;
|
||||
async function bootstrap() {
|
||||
await queue.waitUntilReady();
|
||||
await worker.waitUntilReady();
|
||||
await dispatcher.dispatchBatch();
|
||||
await platformDispatcher.dispatchBatch();
|
||||
await platformScheduler.run();
|
||||
dispatcherTimer = setInterval(
|
||||
() =>
|
||||
() => {
|
||||
void dispatcher.dispatchBatch().catch((error: unknown) => {
|
||||
console.error(
|
||||
'outbox_dispatch_failed',
|
||||
error instanceof Error ? error.message : error,
|
||||
);
|
||||
}),
|
||||
});
|
||||
void platformDispatcher.dispatchBatch().catch((error: unknown) => {
|
||||
console.error(
|
||||
'platform_outbox_dispatch_failed',
|
||||
error instanceof Error ? error.message : error,
|
||||
);
|
||||
});
|
||||
},
|
||||
2_000,
|
||||
);
|
||||
platformCatalogTimer = setInterval(
|
||||
() => void platformScheduler.run().catch((error: unknown) => {
|
||||
console.error('platform_catalog_schedule_failed', error instanceof Error ? error.message : error);
|
||||
}),
|
||||
60_000,
|
||||
);
|
||||
void mediaUploadCleanup.run().catch((error: unknown) => {
|
||||
console.error(
|
||||
'media_upload_cleanup_startup_failed',
|
||||
@@ -329,8 +357,10 @@ void bootstrap().catch((error: unknown) => {
|
||||
async function shutdown() {
|
||||
if (dispatcherTimer) clearInterval(dispatcherTimer);
|
||||
if (mediaCleanupTimer) clearInterval(mediaCleanupTimer);
|
||||
if (platformCatalogTimer) clearInterval(platformCatalogTimer);
|
||||
await worker.close();
|
||||
await queue.close();
|
||||
await platformQueue.close();
|
||||
objectStorage.destroy();
|
||||
await database.close();
|
||||
await connection.quit();
|
||||
|
||||
Reference in New Issue
Block a user