- #130
70cb314
Thanks @charlypoly! - Fix VSCode dynamic imports resolving on@defer/client/index
- #128
17b344f
Thanks @charlypoly! - Regression on locallistExecutions()
- #126
f8a010d
Thanks @charlypoly! - Local support for metadata filtering
-
#125
dc38d60
Thanks @codenem! - Fix InternalExecution interface -
#125
42b943b
Thanks @phil-loops! - update type definition forDeferableFunction
-
#123
cf3b12d
Thanks @charlypoly! - FixawaitResult()
typings
- #120
c1f4ffe
Thanks @charlypoly! - Fix local concurrency applied globally
-
#116
2276048
Thanks @gearnode! - This new major version brings scheduling features to the local developer experience.Features:
- concurrency
- delay
- reschedule
- cancel
- discard
DeferError
has been replaced with respective errors for each client method.
Breaking changes:
getExecution
does not return the result anymore. To do so, one must usegetExecutionResult
.
-
#116
b62b04b
Thanks @gearnode! - Add option to hide defer starting banner -
#116
b62b04b
Thanks @gearnode! - Add option to not start local execution scheduler
- #110
a9055df
Thanks @charlypoly! - Re-throw errors for local development
-
#102
5613d53
Thanks @charlypoly! - AddassignOptions()
helperassignOptions
is helpful to change the behavior of a given Background Function by combining multiple options such asdelay
,metadata
ordiscardAfter
:import { assignOptions, delay } from "@defer/client"; import handleStripeWebhookFn from "./defer/handleStripeWebhook.js"; // ... const handleStripeWebhook = assignOptions(handleStripeWebhookFn, { discardAfter: '12h' // process webhooks in the right order delay: event.created + 60 * 10, // add metadata for the the Defer Console metadata: { livemode: event.livemode, type: event.type, apiVersion: event.api_version, }, }); handleStripeWebhook(event.id) .then((executionID) => { response.sendStatus( 200, "application/json", JSON.stringify({ executionID }) ); }) .catch((err) => { response.sendStatus(400); }); // ...
- #100
4e367da
Thanks @estubmo! - Bun support: Use crypto rather than URL/Blob API for generating random UUID
- #82
73a96d9
Thanks @charlypoly! - Remove unnecessarypeerDependencies
onnext
andreact
-
#80
27a1d46
Thanks @gearnode! - Add cancel execution:import { cancelExecution } from "@defer/client"; // ... const { id } = await cancelExecution(executionId); // ...
- #78
8477826
Thanks @charlypoly! - fix ESM compat
- #76
54ec6f7
Thanks @charlypoly! - Typings fixes on 1.7.0
-
#66
b9973d5
Thanks @charlypoly! - Introducing@defer/client/next
integrationThis release introduces two new helpers that makes Defer deeply integrated with NextJS:
asNextRoute()
: used in combination ofuseDeferRoute()
to trigger background functions from Client-side ComponentsuseDeferRoute()
: trigger and wait for the result of a background functions from Client-side Components
import { asNextRoute } from "@defer/client/next"; import createThumbnails from "../../defer/createThumbnails"; const { GetHandler, PostHandler } = asNextRoute(createThumbnails); export const GET = GetHandler; export const POST = PostHandler;
import { useDeferRoute } from "@defer/client/next"; import createThumbnails from "../../defer/createThumbnails"; export function MyComp() { const { request, loading, result } = useDeferRoute(createThumbnails); return ( <div> <span>Loading: {loading ? "Yes" : "No"}</span> <span>Result: {result ? JSON.stringify(result) : "--"}</span> <button onClick={() => request("")}>Call</button> </div> ); }
-
#70
4646cd0
Thanks @gearnode! - IntroducingmaxDuration
supportdefer()
exposes a newmaxDuration
configuration:const importContacts = (companyId: string, contacts: Contact[]) => { // ... }; export default defer(importContacts, { maxDuration: 10, // timeout after 10secs });
BREAKING CHANGE:
maxDuration
has a default value to 30min. Users having executions going over this limit can override it with a higher value{ maxDuration: 3600 }
- #59
0333c50
Thanks @charlypoly! - Fixretry
default value
-
#36
ccc39dd
Thanks @charlypoly! - exposegetExecution(id)
to poll for an execution status and result:import { type FetchExecutionResponse, getExecution } from "@defer/client"; import type { NextApiRequest, NextApiResponse } from "next"; type Response = { res: FetchExecutionResponse; }; export default async function handler( req: NextApiRequest, res: NextApiResponse<Response>, ) { const executionId = req.query.id; const ret = await getExecution(executionId as string); res.status(200).json({ res: ret }); }
-
#29
859bf46
Thanks @gearnode! - Add concurrency limit option.import { defer } from "@defer/client"; async function oneByOne() { // do something... } export default defer(oneByOne, { concurrency: 1 });
-
#34
fe251f2
Thanks @charlypoly! - BREAKING CHANGE:- Renamed
defer.schedule()
todefer.cron()
defer.cron()
no longer takes a english string but a CRON tab string
import { defer } from "@defer.run/client"; const weeklyBrief = async () => { // ... }; export default defer.cron(weeklyBrief, "5 0 * * *");
- Renamed
-
#34
e399d75
Thanks @charlypoly! - Deprecatedefer.await()
in favor ofawaitResult(deferFn)
import { importContacts } from "../defer/importContacts"; const importContactWithResult = awaitResult(importContacts); const result = await importContactWithResult("1", []);
-
#26
4d2c4d4
Thanks @gearnode! - Add a primary retry option when defining defer function.import { defer } from "@defer/client"; async function makeAPICallWhoMaybeFail() { // do something... } export default defer(makeAPICallWhoMaybeFail, { retry: 5 });
-
#24
ca35544
Thanks @charlypoly! - Introduce a new API to delay an execution:import { delay } from "@defer/client"; import { helloWorld } from "../defer/helloWorld"; // create a delayed execution const delayedHelloWorld = delay(helloWorld, "1h"); delayedHelloWorld(); // background execution in 1 hour
-
#20
99ed4df
Thanks @charlypoly! - Introducedefer.schedule(fn, frequencyStr)
Defer now support scheduled functions (CRON), as follows:
import { defer } from "@defer/client"; async function myDeferWorkflow() { const users = await prisma.user.find({ where: { // ... }, }); // do something... } export default defer.cron(myDeferWorkflow, "every day at 10am");
Notes
- a scheduled function should not take arguments
- a scheduled function is scheduled on UTC time
- a scheduled function should not be invoked (will result in errors)
- #18
27fe426
Thanks @charlypoly! - Typings fixes
- #16
e282ee3
Thanks @charlypoly! - Handle error without result on polling
- #14
2007397
Thanks @charlypoly! -DeferFunction.await()
should be noop whenDEFER_TOKEN
is not set
- #11
9c7895c
Thanks @charlypoly! - Support for delayed functions
- #12
5cde47b
Thanks @charlypoly! - Forward the received error fordeferred.await()
- #4
08f0945
Thanks @charlypoly! -defer.await()
- #8
991697d
Thanks @charlypoly! - expose client version (internal)
- #9
87ea1d4
Thanks @charlypoly! - Execution polling jitter algorithm
- support multiple arguments + error handling
- ESM fix
- major bugfix
- fetch
- debug mode
- fix for fetch client (POST)