0.0.1 • Published 10 months ago

@affenity/simplebull v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

SimpleBull

A highly opinionated, highly simplistic, highly not recommended for anyone else to use, library that looks like inngest.com and trigger.dev, but is free, straightforward to use, and are built on top of existing tools.

(Also meaning it's simple as heck to self-host. Just use Redis and BullMQ).

This is meant more like a proof oc concept, and not a production ready library.

Installing

bun add simplebull

Usage

//> Declaring an "Action" (Queue & Worker)
const processVideo = SimpleBull.action(
    {
        slug: "process-video",
        schema: z.object({
            videoUrl: z.string()
        })
    },
    {
        jobs: {
            retries: {
                max: 3,
                delay: 1000,
                backoff: "fixed"
            }
        }
    },
    async ({ ctx, job, runner, data }) => {
        const downloadVideo = await runner.step(
            { id: "download-video" },
            () => downloadVideoFromUrl(data.videoUrl)
        );

        const transcodeVideo = await runner.step(
            { id: "transcode-video" },
            () => transcodeVideo(downloadVideo)
        );

        const generateTranscripts = await runner.step(
            { id: "generate-transcripts" },
            () => generateTranscripts(transcodeVideo)
        );

        const writeToDb = await runner.step(
            { id: "write-to-db" },
            () => db.video.create({
                downloadedId: downloadVideo.id,
                transcriptsLocation: generateTranscripts.location,
                transcodedVideoLocation: transcodeVideo.location
            })
        );

        return {
            dbId: writeToDb.id
        };
    }
);

//> Initiating
const client = SimpleBull.client({ redisUrl: "redis://" });
await client.init(); //> This prepared the bullmq queues and workers
await client.start(); //> This starts them for work

//> Adding a job
processVideo.addJob({
    videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
});

As you can see, each step is run redundantly, and if any step fails, the previous successful steps won't be run again, and the job will start from the failed step.

0.0.1

10 months ago