@stackshift-cloud/jobs
v0.1.1
Published
TypeScript SDK for StackShift Durable Jobs.
Readme
@stackshift-cloud/jobs
TypeScript SDK for StackShift Durable Jobs.
import { StackShift } from '@stackshift-cloud/jobs'
const stackshift = new StackShift()
await stackshift.queue('emails').enqueue('sendWelcomeEmail', {
userId: '123'
}, {
idempotencyKey: 'welcome-email:123',
idempotencyTtl: '30d'
})
stackshift.job('new-customer-onboarding', async ({ step }) => {
await step.run('create-account', createAccount)
await step.run('provision-instance', provisionInstance)
await step.run('send-welcome-email', sendWelcomeEmail)
await step.waitForEvent('first-payment-confirmed', {
correlationKey: 'customer:123',
timeout: '24h',
onTimeout: 'fail'
})
await step.run('unlock-features', unlockFeatures)
})StackShift invokes registered job handlers through a language-neutral HTTP callback. In Node runtimes, expose a route that calls handleInvocation and return its status/body:
export async function POST(request: Request) {
const invocation = await request.json()
const { status, body } = await stackshift.handleInvocation(invocation)
return Response.json(body, { status })
}Pass that route as handlerUrl when starting or enqueueing a run.
External systems can resume a waiting workflow by sending a correlated event:
await stackshift.events.send(
'email.verified',
{ userId: 'user_123', verifiedAt: new Date().toISOString() },
{
correlationKey: 'user:user_123',
idempotencyKey: 'email.verified:user_123',
idempotencyTtl: '30d'
}
)