Replies: 10 comments 40 replies
-
Definitely |
Beta Was this translation helpful? Give feedback.
-
You can spin up Quirrel as a Docker image on Fly.io. Here's an article. He spins up his own Redis instance, but you can also connect to Fly's Upstash Redis for free. |
Beta Was this translation helpful? Give feedback.
-
In a monorepo setup, the |
Beta Was this translation helpful? Give feedback.
-
How about using supercronic in a fly process (https://fly.io/docs/app-guides/supercronic/ ) and use getInstanceInfo from 'litefs-js' to only run on the primary (the latter is already in use in the project - e.g. in entry.server.tsx) ?
|
Beta Was this translation helpful? Give feedback.
-
I use BullMQ to handle my background jobs. It does require spinning up a redis instance, but that's a one line deploy on Fly and all my app regions can talk to the same redis instance since latency stops being a factor in background jobs On the developer's side, usage is simple enough: import the queue and add new docs to it import { emailQueue } from "./queue.server"
await emailQueue.add("send-welcome-email", {
to: "[email protected]",
subject: "Welcome to our app!",
text: "Thanks for signing up!",
}) import { renderQueue } from "./queue.server"
const job = await renderQueue.getJob("123")
console.log(job.progress) // 0.5
console.log(job.returnvalue) // undefined
const TIMEOUT_MILLISECONDS = 30 * 1000
await job.waitUntilFinished(
renderQueue.events,
TIMEOUT_MILLISECONDS,
)
console.log(job.progress) // 1
console.log(job.returnvalue) // { url: "123.png" } |
Beta Was this translation helpful? Give feedback.
-
I looked at bree, toad-scheduler, and croner. Out of those I think croner is a good starting point that would fit the stated goals. I'm currently leaning epic-stack + croner + a db table to track executions and which server instance owns each job. I'm new to everything, what file would start the jobs? In my testing I've been using ./server/index.ts |
Beta Was this translation helpful? Give feedback.
-
@kentcdodds Are there any updates on this? I want to add cron jobs to my Epic Stack derived project. |
Beta Was this translation helpful? Give feedback.
-
If anyone is looking for a more robust solution, trigger.dev has been my go to recently |
Beta Was this translation helpful? Give feedback.
-
If you need something simple:
Works pretty well for me. Example, if you want to send an email sequence: model EmailSchedule {
id String @id @default(cuid())
createdAt DateTime @default(now())
to String
sequence Int
scheduledAt DateTime
sent Boolean @default(false)
@@unique([to, sequence])
} On some action, call scheduleEmailSequence(email): async function scheduleEmailSequence(email: string) {
const now = new Date()
const in1Day = new Date(now.getTime() + 1 * 24 * 3600 * 1000)
const in2Days = new Date(now.getTime() + 2 * 24 * 3600 * 1000)
const in3Days = new Date(now.getTime() + 3 * 24 * 3600 * 1000)
const in4Days = new Date(now.getTime() + 4 * 24 * 3600 * 1000)
const scheduleDates = [in1Day, in2Days, in3Days, in4Days]
for (let i = 0; i < scheduleDates.length; i++) {
const scheduledAt = scheduleDates[i]
const sequence = i + 1
await prisma.emailSchedule.upsert({
where: {
to_sequence: {
to: email,
sequence,
},
},
update: {
scheduledAt: scheduledAt,
},
create: {
to: email,
sequence,
scheduledAt: scheduledAt,
},
})
}
} root.tsx: new CronJob(
'* * * * *', // cronTime
async function () {
// Check if there are emails in the queue
const emailsToSend = await prisma.emailSchedule.findMany()
// etc...
}, // onTick
null, // onComplete
true, // start
'America/Los_Angeles', // timeZone
) |
Beta Was this translation helpful? Give feedback.
-
Has anyone had any experience with https://worker.graphile.org/ ? |
Beta Was this translation helpful? Give feedback.
-
First of all, lots of cool ideas here, thank you for sharing it with the world.
One common use case I'm not seeing a solution for in the roadmap yet (though I may have missed it): Are there plans to support cron jobs (scheduled tasks), background jobs, etc?
Things like: "At 5am, compute and send this daily report to all subscribers"
This would help performance by offloading computationally intensive tasks. It would also be useful for common scenarios from automating routine maintenance tasks to queueing up and performing long-running work in the background.
Any plans for supporting this?
Beta Was this translation helpful? Give feedback.
All reactions