@amplience/dc-cli
Version:
Dynamic Content CLI Tool
46 lines (45 loc) • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContentItemSyncService = void 0;
const dc_management_sdk_js_1 = require("dc-management-sdk-js");
const burstable_queue_1 = require("../../common/burstable-queue/burstable-queue");
const promises_1 = require("node:timers/promises");
const DELAY = 200;
class ContentItemSyncService {
constructor() {
this._failedJobs = [];
this.queue = new burstable_queue_1.BurstableQueue({ concurrency: 1 });
}
sync(destinationHubId, hub, contentItem, action, options) {
this.queue.add(async () => {
var _a;
const createSyncJob = await hub.related.jobs.createDeepSyncJob(new dc_management_sdk_js_1.CreateDeepSyncJobRequest({
label: `dc-cli content item: ${contentItem.label}`,
ignoreSchemaValidation: (_a = options.ignoreSchemaValidation) !== null && _a !== void 0 ? _a : true,
forceSync: options.forceSync || false,
destinationHubId,
input: { rootContentItemIds: [contentItem.id] }
}));
const completedJob = await this.waitForJobCompletion(createSyncJob.jobId, hub);
if (completedJob.status === 'FAILED') {
this._failedJobs.push(completedJob);
}
action(completedJob);
});
}
async waitForJobCompletion(jobId, hub) {
let syncJob = await hub.related.jobs.get(jobId);
while (syncJob.status === 'CREATED' || syncJob.status === 'IN_PROGRESS') {
await (0, promises_1.setTimeout)(DELAY);
syncJob = await hub.related.jobs.get(syncJob.id);
}
return syncJob;
}
async onIdle() {
return this.queue.onIdle();
}
get failedJobs() {
return this._failedJobs;
}
}
exports.ContentItemSyncService = ContentItemSyncService;