import { last } from '@welshman/lib' import type { Subscription } from './alert.js' import { getSubscriptionByKey } from './database.js' import { runJob } from './worker/email.js' const key = last(process.argv) if (!key) { console.error('Please provide a subscription key') process.exit(1) } getSubscriptionByKey(key) .then((sub: Subscription | undefined) => { if (!sub) { console.error('Invalid subscription key') return false } return runJob(sub) }) .then((success: boolean) => { process.exit(success ? 0 : 1) }) .catch((error: Error) => { console.error(error) process.exit(1) })