SvelteKit and background workers #12927
Replies: 3 comments 8 replies
-
@0x2E thank you for the reply! The custom server is probably one option to solve it, but it doesn't really allow to do the second thing I mentioned:
Let's say you want to use a // somewhere in the src/ directory
import { domainsRepository } from '$lib/server/DomainsRepository'; // <-- how would you import this?
import { REDIS_HOST, REDIS_PORT } from "$env/static/private";
import { ConnectionOptions, Worker, Job } from "bullmq";
async function main() {
const connection: ConnectionOptions = {
// ...options
}
new Worker('crawl-domain', async (job: Job) => {
const { domainId } = job.data
const domain = domainsRepository.getDomainById(domainId)
// Crawl the domain
return 'done';
}, { connection });
} For now the only way I see it is extracting the server logic into a separate npm workspace, and then using it as npm package in the SvelteKit app and in the background workers (which would be separate app as well). But the Django way to do this just seems so much easier to use. |
Beta Was this translation helpful? Give feedback.
-
No updates on this one? |
Beta Was this translation helpful? Give feedback.
-
Hello there 👋
So, I've been using the SvelteKit for my own projects for some time, and for my last use case, I stumbled on a following question:
What is the "proper" way to execute .ts scripts in a sveltekit project?
Think of something like "management commands" concept in Django applications:
Example:
Starting background worker for processing the message queue:
src/lib/commands/bg_worker.ts
:package.json
:Think about any other type of background jobs you might have to do on your backend. Workarounds and hacks are welcomed, but I'm mostly interested in finding out what is the "proper", SvelteKit way of doing it.
Update:
All thanks to @david-plugge:
#9807 (comment). vite-node solved it for me.
Beta Was this translation helpful? Give feedback.
All reactions