-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] deno #224
Comments
What would you need from this library to allow it to work in deno? |
Hello @jbielick, regarding the latest compatibility from https://deno.land/std@0.119.0/node/README.md, it might work as it with the compat flag 😄 |
Great news, it seems to work in Deno now using the latest stuff!
Run this command for the job pusher: // faktory.js
import { createRequire } from "https://deno.land/std@0.125.0/node/module.ts";
const require = createRequire(import.meta.url);
const faktory = require('faktory-worker');
try {
const client = await faktory.connect();
await client.job("ResizeImage", { id: 333, size: "thumb" }).push();
await client.close(); // reuse client if possible! remember to disconnect!
} catch (e) {
console.error(e);
}
console.log('finished'); Run this for the worker: //faktory-worker.js
import { createRequire } from "https://deno.land/std@0.125.0/node/module.ts";
const require = createRequire(import.meta.url);
const faktory = require('faktory-worker');
faktory.register("ResizeImage", async ({ id, size }) => {
await new Promise((resolve) => {
setTimeout(() => {
console.log('waiting for id of ',id,' and size ',size);
resolve();
}, 1000);
});
});
faktory.work().catch(error => {
console.error(`worker failed to start: ${error}`);
process.exit(1);
}); jbielick it looks like there is enough Node compatibility to finally make this thing work! It would be cool to consider it a supported platform, and I will deprecate my own Deno-specific library. It is not nearly as feature-rich or stable as this project 😅 |
Here's what I would recommend for Deno on latest versions. // producer.ts
import { Client as FaktoryClient } from "npm:faktory-worker";
const client = new FaktoryClient();
await client.connect();
const job = client.job("ResizeImage", { id: 333, size: "thumb" });
await job.push();
await client.close() // receiver.ts
import { Worker as FaktoryWorker } from "npm:faktory-worker";
const worker = new FaktoryWorker();
worker.register("ResizeImage", async ({ id, size }) => {
const image = await Image.find(id);
await image.resize(size);
});
try {
await worker.work();
} catch (error: unknown) {
console.error(`worker failed to start: ${error}`);
Deno.exit(1);
} If you need an example of usage, I have a project that I recently migrated to this dependency. |
I would love to see this project ported to deno.
There's actually an existing project but having both project maintained at the same place seems to me a better choice for the long term.
Here's a ressource that might help https://medium.com/samsung-internet-dev/using-node-modules-in-deno-2885600ed7a9
The text was updated successfully, but these errors were encountered: