this is how I'm restoring it:
const { url } = job.data;
this.logger.log(`Processing job ${job.id} for URL: ${url}`);
// Capture 'this.logger' to use inside action implementations
const logger = this.logger;
// Provide actual implementations to the machine
const machineWithImplementations = websiteAnalysisMachine.provide({
actions: {
logStart: () => {
logger.log('Starting website analysis');
},
logCompletion: () => {
logger.log('Website analysis completed');
},
logError: ({ context }) => {
logger.error('Error in website analysis:', context.error);
},
},
actors: {
crawlWebsite: fromCallback(({ sendBack, input }) => {
(async () => {
try {
console.log('we are in here');
const data = await this.websiteAnalysisService.crawlWebsite(
input.url,
input.currentProgress || 0, // Use current progress
(progress) => {
sendBack({ type: 'CRAWL_PROGRESS', progress });
},
);
sendBack({ type: 'CRAWL_COMPLETE', data });
} catch (error) {
sendBack({ type: 'FAIL', error: error.message });
}
})();
}),
analyzeContent: fromPromise(async ({ input }) => {
try {
const data = await this.websiteAnalysisService.analyzeContent(
input.url,
);
return data;
} catch (error) {
throw error;
}
}),
analyzeBacklinks: fromPromise(async ({ input }) => {
try {
const data = await this.websiteAnalysisService.analyzeBacklinks(
input.url,
);
return data;
} catch (error) {
throw error;
}
}),
generateSEOReport: fromPromise(async ({ input }) => {
try {
const { contentAnalysis, backlinkData } = input;
const report = await this.websiteAnalysisService.generateSEOReport(
contentAnalysis,
backlinkData,
);
return report;
} catch (error) {
throw error;
}
}),
},
});
// Get persisted snapshot if it exists
const persistedSnapshot = await this.getPersistedSnapshot(job.id);
const actor = createActor(machineWithImplementations, {
input: { jobId: job.id, url },
snapshot: persistedSnapshot,
});