Comments (4)
Thanks @charlypoly! I think this gives me what I need.
from defer.client.
Hi @pangolingo!
Thank you for your detailed feedback!
I have a follow-up question: what would be your expectations for a proper Defer local setup?
Some of my jobs are not appropriate to run locally - for example it may be a long-running job called from a serverless function with a short timeout
It is not documented yet, but the @defer/client
exports a deferEnabled()
function that could be used for this use case to conditionally execute or not a background function locally. What do you think?
from defer.client.
I have a follow-up question: what would be your expectations for a proper Defer local setup?
- I'd expect a warning if no ENV variable is set when running a Deferred function
- I'd expect a way to opt out (or opt in) to running the function locally/synchronously (I envision
runLocally: process.env.NODE_ENV !== 'production'
. Maybe ifrunLocally
is explicitly set then there is no warning? Or mayberunLocally
has multiple options:never
,always
,fallback
. It would be nice if this could be set globally instead of per function.
It is not documented yet, but the @defer/client exports a deferEnabled() function that could be used for this use case to conditionally execute or not a background function locally. What do you think?
So deferEnabled()
is a way to check whether functions will be run locally or not (whether the ENV variable is set)?
Is this how I'd use it?
// force this function to only run if Defer is set up properly
if (deferEnabled()) {
defer(helloWorld);
}
from defer.client.
- I'd expect a warning if no ENV variable is set when running a Deferred function
Since v1.15.0, @gearnode added a hint that the @defer/client
prints when no DEFER_TOKEN
is present (for local dev)
I'd expect a way to opt out (or opt in) to running the function locally/synchronously (I envision runLocally: process.env.NODE_ENV !== 'production'. Maybe if runLocally is explicitly set then there is no warning? Or maybe runLocally has multiple options: never, always, fallback. It would be nice if this could be set globally instead of per function.
So
deferEnabled()
is a way to check whether functions will be run locally or not (whether the ENV variable is set)?
Yes, deferEnabled()
helps to know if the Defer Functions will run locally or on the Defer platform.
Example:
src/api/hello.ts
import { deferEnabled } from '@defer/client'
import longRunningJob from '../defer/longRunningJob'
export default async function handler(req, res) {
// ...
if (deferEnabled()) { // when deployed on staging, production
await longRunningJob()
} else {
// return a mock response for local env
}
// ...
}
from defer.client.
Related Issues (19)
- gzip requests
- Web documentation is unreachable HOT 3
- `failed to detect package manager` HOT 2
- Build logs link have console issues HOT 3
- Can't use client in non-node environments because of "node:url" import and `process.env` HOT 4
- Getting execution result back from defer HOT 3
- getExecution freezes up when in development HOT 1
- Firebase issue HOT 1
- HTTP client receives 200 response with no data when checking execution status HOT 6
- Remix - No matching export for import "randomUUID" HOT 5
- [feat]: ignore test files in defer directory HOT 2
- Add retry on enqueue
- `awaitResult(deferFn, { waitRetries: true })`
- Implement Webhooks functionality to watch for execution status changes HOT 2
- Import ENV variables in bulk by pasting .env file content HOT 4
- URL.createObjectURL not yet supported by Bun - Leading to functions not working in local development HOT 1
- Concurrency option ignored in local dev HOT 1
- Defer gives an error when running in edge mode in a Next.js app on Vercel HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defer.client.