Skip to content
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

agendash not working with this fork #27

Closed
adam91holt opened this issue Jun 14, 2022 · 2 comments
Closed

agendash not working with this fork #27

adam91holt opened this issue Jun 14, 2022 · 2 comments

Comments

@adam91holt
Copy link

Hi,

Thanks for forking this, it's solved some issues I was having with the original package.

One thing I can't get to work is agendash via Fastify which was working previously.

The error I get is about the collection being undefined.

(node:41832) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'collection' of undefined
    at getOverview (C:\ProtempoCoding\job.scraping.manager\node_modules\agendash\lib\controllers\agendash.js:125:43)
    at api (C:\ProtempoCoding\job.scraping.manager\node_modules\agendash\lib\controllers\agendash.js:262:7)
    at Object.<anonymous> (C:\ProtempoCoding\job.scraping.manager\node_modules\agendash\lib\middlewares\fastify.js:27:33)
    at preHandlerCallback (C:\ProtempoCoding\job.scraping.manager\node_modules\fastify\lib\handleRequest.js:126:28)
    at preValidationCallback (C:\ProtempoCoding\job.scraping.manager\node_modules\fastify\lib\handleRequest.js:109:5)
    at handler (C:\ProtempoCoding\job.scraping.manager\node_modules\fastify\lib\handleRequest.js:72:7)
    at handleRequest (C:\ProtempoCoding\job.scraping.manager\node_modules\fastify\lib\handleRequest.js:20:5)
    at runPreParsing (C:\ProtempoCoding\job.scraping.manager\node_modules\fastify\lib\route.js:451:5)
    at Object.routeHandler [as handler] (C:\ProtempoCoding\job.scraping.manager\node_modules\fastify\lib\route.js:409:7)
    at Router.lookup (C:\ProtempoCoding\job.scraping.manager\node_modules\find-my-way\index.js:378:14)
(node:41832) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

It worked fine on the standard agenda setup. I'm thinking it's likely to do with the increased mongodb sdk version?

Here is some example code.

import { Agenda } from "@hokify/agenda";
import config from "config";

const Agendash = require("agendash");
const Fastify = require("fastify");

const mongoConnectionStringAgenda: string = config.get("agenda.db.uri");
const agenda = new Agenda({
  db: { address: mongoConnectionStringAgenda, collection: "agendaJobs" },
});
const fastify = new Fastify();
fastify.register(Agendash(agenda, { middleware: "fastify" }));


agenda.define(
  "start company jobs",
  async (job) => {
console.log(job)
  },
  { priority: 20 }
);

// Get jobs on first run
async function init() {
  // Start web server for monitoring
  await fastify.listen(3002);
  console.log("Listening on port 3002");
  // Start agenda process
  await agenda.start();

  console.log("Agenda started");
  await agenda.purge();
  // Start jobs
  agenda.now("start company jobs", {});

}
init();

Thanks

@fhawkes
Copy link

fhawkes commented Jul 16, 2022

@adam91holt I created a fork a while ago to get agendash working with this fork. I can't promise it will stay up to date, but its working https://github.com/soundbeef/agendash

@simllll
Copy link
Contributor

simllll commented Aug 2, 2022

Thanks @fhawkes
in agendats (@hokify/agenda) the database layer is abstracted, to access the "collection" directly, you can use:
const collection = agenda.db.collection; to get access to the underlying database connection.
Or use the same logic as fhawkes did, for example here: https://github.com/soundbeef/agendash/blob/0a0cfae7f3c8ee7b7f90876a31dea91ba5b035c6/lib/controllers/agendash.js#L8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants