Go event-driven for reliability
Things break, it’s a fact of life. Sailhouse helps you ride out the bumps.
sailhouse.subscribe('document.uploaded', 'analyze', async ({event}) => {
const { documentId, content, userId } = event;
const { text } = await generateText({
model: openai("gpt-4"),
prompt: `Analyze this document and extract key insights: ${content}`
});
await saveAnalysis(documentId, text);
});
Increase performance by shifting work to the background
Speed things up by offloading tasks to the background.
app.post('/documents', async (req, res) => {
const { documentId, content } = req.body;
await sailhouse.publish('document.uploaded', {
documentId,
content,
userId: req.user.id
});
res.json({
message: "Document queued for processing",
documentId
});
});
Build new features fast, without messy code
Events make it easy to scale a code base. Want a new feature? Just add a subscriber without impacting your users.
sailhouse.subscribe('document.uploaded', 'notify', async ({event}) => {
const { documentId, userId } = event;
await sendNotification(userId, `Your document ${documentId} has been uploaded`);
});