sveltejs / sveltejs/kit

Add support for scheduled functions

Open
#10,477 6 comments 26 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-decision
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed src/routes/+cron//+server.ts structure and the Netlify adapter prototype referenced in #10471. Review how scheduled-function output would need to work across adapters; done means the proposed platform-agnostic scheduled route structure is supported by the relevant adapters.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.