elysiajs / elysia-cron

Plugin for Elysia that add support for running cronjob
MIT License
14 stars 6 forks source link

Feature request: Access app states + decorator in the cron handler #30

Open KONFeature opened 3 weeks ago

KONFeature commented 3 weeks ago

What is the problem this feature would solve?

Would be awesome to have access to the current instance sstore + decorators in the cron handler.

As of right now, I'm using smth like this to retrieve params from decorators / store :

const baseApp = new Elysia().decorate({someStuff: "test"})

export const demoCron = (app: typeof baseApp) => app.use(
    cron({
        name: "demo",
        pattern: Patterns.everyMinutes(30),
        run: async () => {
            // Get some stuff from the app
            const {
                someStuff
            } = app.decorator;
        },
    })
)

Not a huge fan of this design (but it's working) I've tried a few different way to "correct" this, by implementing custom cron, with custom generics etc, but tbh I'm new to Elysia and a bit lost in it's types ahah

What is the feature you are proposing to solve the problem?

Updating the cron run method of the cron plugin, to accept the current Elysia instance store + decorators as params

What alternatives have you considered?

No response