Coder Social home page Coder Social logo

defer-run / defer.client Goto Github PK

View Code? Open in Web Editor NEW
211.0 211.0 4.0 879 KB

Zero infrastructure Node.js background jobs

Home Page: https://www.defer.run/docs/introduction

License: ISC License

TypeScript 94.13% JavaScript 5.87%
background-jobs cron nodejs queueing typescript

defer.client's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

defer.client's Issues

Implement Webhooks functionality to watch for execution status changes

Hi,
Wouldn't it be cool if Defer.run would provide a way to set up webhooks (like Stripe does) to listen to the execution status changes via some endpoint.

This endpoint could return the usual stuff: id, state, result plus the metadata provided when invoking the function. This would allow to set a custom data like userEmail and send an email automatically once webhook is called.

Currently, I have to store the execution ID in the database, and check the getExecution method periodically in a cron job to check if the status is changed (unless there's a better way to do it).

Let me know what you think.
Thanks

Import ENV variables in bulk by pasting .env file content

Hi,
Would be great if I could paste the contents of .env file to import all of the variables.
My project has lots of them and adding them one by one is pretty time consuming.

You can check how Vercel does that in their panel.

PS. If there's better way to report feature requests, please let me know.

Thanks!

URL.createObjectURL not yet supported by Bun - Leading to functions not working in local development

Trying to setup Defer to run with Bun and Elysia, but ending up with this error when following the helloWorld quick-start:

[0] TypeError: undefined is not an object (evaluating 'URL.createObjectURL(new Blob([])).slice')
[0]       at randomUUID (/home/emo/projects/ff-server/node_modules/@defer/client/esm/index.js:9:11)
[0]       at /home/emo/projects/ff-server/node_modules/@defer/client/esm/index.js:131:19
[0]       at ret (/home/emo/projects/ff-server/node_modules/@defer/client/esm/index.js:111:16)
[0]       at /home/emo/projects/ff-server/src/controllers/defer.tsx:13:19
[0]       at /home/emo/projects/ff-server/src/controllers/defer.tsx:11:4
[0]       at processTicksAndRejections (:55:76)
[0]
[0] 2023-09-25T18:13:42.299ZUTC | GET /api/defer - 500 (5 ms)

This is only happening during local development.

const randomUUID = () => {
    return URL.createObjectURL(new Blob([])).slice(-36);
};

And although URL is marked as fully compatible with Node in the Bun docs, that doesn't seem to be entirely true, as Jarred has said it's not yet implemented. Here's a tracking issue.

The obvious solution would be to use something other than the Node URL and Blob API's to make a UUID.

Web documentation is unreachable

Hello guys! ๐Ÿ‘‹

I'm trying to browse your online documentation at https://docs.defer.run/ but I'm getting 503 errors.
Please find the full error message on this page: https://docs.defer.run/getting-started/1-create-application/

503 ERROR
The request could not be satisfied.
The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
Generated by cloudfront (CloudFront)
Request ID: gzET2SfCr8HpaTQQ902FGVJlL6PvO6uiHETAA2VqxTQjJIm37rJeOg==

Have a great day and good luck on your journey!

Firebase issue

I'm trying to use the Firebase Admin SDK inside a function that gets called in Defer. However, it's not able to parse the private key env variable. Works fine in Vercel but the defer environment must handle the private key differently.

It's in this format: "-----BEGIN PRIVATE KEY-----\nKEY\n-----END PRIVATE KEY-----\n"

Defer gives an error when running in edge mode in a Next.js app on Vercel

I'm attempting to run a Defer function in a Route Handler (formerly called API Route) in my Nextjs app. For performance reasons I marked this API function as using the "edge" runtime instead of the default "nodejs" runtime. This results in an error when I run the function.

Expected behavior:
There are no errors when running a Defer function on the edge runtime.

Actual behavior:
I see an error when running the Defer function. This error occurs in the Next.js app, and the function is never run on Defer's side.

Error: invalid request body: function_name is missing or empty
    at (node_modules/@defer/client/esm/httpClient.js:83:18)
    at (src/app/api/background-job/route.ts:7:17)
    at (node_modules/next/dist/esm/server/future/route-modules/app-route/module.js:189:36) {
  code: 'bad_request'
}

Workarounds:
If I change the route back to using the Node.js runtime, it runs without errors

Observations:
The error message appears to indicate that Defer isn't able to figure out the function's name.

Docs for the edge runtime:
https://nextjs.org/docs/app/building-your-application/routing/route-handlers#edge-and-nodejs-runtimes
https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes

Code sample:
This is the Next.js route file - it's pretty simple:

import helloWorld from "@/defer/helloWorld";

export const dynamic = "force-dynamic"; // defaults to auto
export const runtime = "edge"; // 'nodejs' is the default

export async function POST(request: Request) {
  const result = await helloWorld("Dave");

  console.log("result", result);

  return new Response(JSON.stringify({ result }), {
    headers: { "Content-Type": "application/json" },
  });
}

Build logs link have console issues

Hello Team,

https://app.defer.run/applications/2LzXGMiExoerd1dbGwJjUs5p9Ya/build/2LzzrTgBlXQ1FQV2EiamXMHnudg

The page rendering on above link have some issues related to react, please fix it!

React Router caught the following error during render TypeError: Cannot read properties of null (reading 'compileCommandLog')
    at gS (Build.tsx:146:13)

I click on above link from below page's commit build status link:
pnutmath/defer-demo@da977a5

@charlypoly Do we support only Typescript for this? No Plain JavaScript?

getExecution freezes up when in development

I have the following code, when this is run on local development, getExecution never returns.

Screenshot 2023-03-15 at 2 16 47 PM

Another strange thing is the jobs that are created, no matter how many, return all the same executionId of 00000000000000000000000000000000

[feat]: ignore test files in defer directory

I'm getting an error about Vitest because I have a .test.ts file adjacent to my defer function (which is usually fine). Would be great if **.test** files were ignored in the build process.

Concurrency option ignored in local dev

The defer client ignores the concurrency setting when executing jobs locally, and instead immediately invokes the handler function unconditionally, regardless of how many other invocations of the handler are already running.

defer.client/src/index.ts

Lines 104 to 109 in 301f78e

debug(`[defer.run][${originalFunction.name}] defer ignore, no token found.`);
const id = randomUUID();
__database.set(id, { id: id, state: "started" });
execLocally(id, originalFunction, functionArguments);
return { id };

Proper concurrency control is critical to my use case, and it's impossible to develop and test my code if this option does not work.

It would not be hard for the client to maintain an in-memory queue in order to ensure that only concurrency invocations of a job run at a time in dev.

This missing functionality is also not documented anywhere in the local dev docs or concurrency option docs.

Remix - No matching export for import "randomUUID"

Hi, I've run into trouble while trying to set up hello world example as a background job in Remix.

Whenever I try to run the server, it crashes with the following error:

No matching export in "../../node_modules/esbuild-plugin-polyfill-node/polyfills/empty.js" for import "randomUUID"
dev: 
dev:     ../../node_modules/@defer/client/esm/index.js:2:9:
dev:       2 โ”‚ import { randomUUID } from "crypto";

Any idea why?
Thanks!

Defer ignores an absent ENV variable

Current behavior:
If the DEFER_TOKEN environment variable is absent, a deferred function will run locally with no indication that it is not running as a background job.

Expected behavior:
If the deferred function could not be run as a background job on Defer's infrastructure because of a missing/misconfigured environment variable or some other reason, an error should be thrown.

Or at minimum the user should be able to specify that the function should or should not fall back to running locally.

Steps to reproduce:

  1. Add the Defer library
  2. Do not add a DEFER_TOKEN environment variable
  3. Write a deferred function
  4. Call the deferred function
  5. Check the logs for errors

Explanation:
I'd like to see a log or error message to indicate that I didn't set up Defer correctly.
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

HTTP client receives 200 response with no data when checking execution status

I'm having a weird error where the status of a job is unable to be fetched after it succeeds. I've tracked it down to the HTTP client in this library getting a 200 response albeit with no data. I'm therefore unable to get the results of the execution. This only happens on successful executions, not failures.

Getting execution result back from defer

I'm using nextjs and trpc. I like that defer can take my expensive api call to openai and execute it for me, but I'm running into the issue where when that result is ready, how do I let my nextjs server know about it right away?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.