Skip to content

Add support for scheduled functionsΒ #10477

Open
@Samuel-Martineau

Description

@Samuel-Martineau

Describe the problem

As SvelteKit projects are often deployed in serverless environments, tools like node-cron are not really usable, and makes scheduled tasks quite hard to implement.

Fortunately, many serverless deployment environments now have built-in support for this, for example Netlify. However, integrating those functionality into SvelteKit projects is currently not trivial, as the different adapters are not built to output in the required formats.

Describe the proposed solution

To make those scheduled functions as easy to implement as possible and to keep them in style with current SvelteKit features, I suggest to define them using a directory-based structure.

My current idea is to have a special folder named +cron that contains the different time rules as folders with their names in a crontab syntax, with spaces replaced with underscores. The actual function to be triggered would simply be placed in a regular +server.{js|ts} file, which would export a single (perhaps POST) endpoint.

src
`-- routes
    `-- +cron
        `-- 2_20_*_*_*
            `-- +server.ts

This would allow for an intuitive platform-agnostic way to define scheduled functions.

Importance

would make my life easier

Additional Information

#10471 is a prototype implementation of this feature request for Netlify via the @sveltejs/adapter-netlify.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature / enhancementNew feature or requestneeds-decisionNot sure if we want to do this yet, also design work needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions