Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Allow API routes to optionally run as background function #166

Closed
colinwirt opened this issue Feb 8, 2021 · 3 comments · Fixed by #171
Closed

Allow API routes to optionally run as background function #166

colinwirt opened this issue Feb 8, 2021 · 3 comments · Fixed by #171
Labels
priority: low type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@colinwirt
Copy link

Is your feature request related to a problem? Please describe.
Some API routes we build start out nice and simple.
As we complete integrations with 3rd party systems (SAP for example), the tasks these need to perform can unexpectedly grow in complexity. Especially where client-side systems already exist to handle functionality and a client decides not to streamline or rebuild slow-running BAU systems.

Describe the solution you'd like
It would be simple to be able to define a Next API route that we discover needs to run for more than 10 seconds to run as a background function.

Describe alternatives you've considered

  1. Fork this package.
  2. Work completely outside Next.js -- creating a custom serverless function that resides as a separate piece of work. Write this in my own time because I enjoy creating simple side-projects.

Additional context

  • Most of our serverless code is deployed as API routes built by next-on-netlify, having a single background function implemented outside next-on-netlify creates an unfamiliar pipeline that complicates the onboarding process.
  • I've created a version of this package that allows an API route to include the string -background to keep all our API routes in a common build step.
@lindsaylevine lindsaylevine added priority: low type: feature code contributing to the implementation of a feature and/or user facing functionality labels Feb 9, 2021
@lindsaylevine
Copy link
Contributor

lol hello again colin! i thought i recognized your name 😸 (original ask for reference #127)

so you're imagining a file in pages/api named something like users-background.js ?

@colinwirt
Copy link
Author

Yes, that's right @lindsaylevine -- in fact that's how I've deployed the long running endpoint for my proof of concept using a fork of this package: a route called /api/contact-us-background

Using TypeScript meant it was non-trivial to extract this as a js function without a webpack step, so my first thought was to allow the name to include the -background suffix.

@lindsaylevine
Copy link
Contributor

@colinwirt ok, yes, we can do this! but i'll restrict it to api pages only. your original PR would've in theory allowed for any page type to run as a background function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority: low type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants