Git Product home page Git Product logo

Comments (6)

xts-bit avatar xts-bit commented on June 2, 2024

@simllll Simon, I'm sure that the problem is related to the MongoDB connection because the job doesn't run at the given time, But as soon as i start my server it runs the job

from agenda.

xts-bit avatar xts-bit commented on June 2, 2024

@simllll @harisvsulaiman @koresar Is there anyone who can help me with this Please?

from agenda.

simllll avatar simllll commented on June 2, 2024

Unfortuantely we cannot help everyone to solve their problems on-hand.
What you can do:
1.) Write a mini repo script that reproduces the issue to track it down, without any other magic.
2.) Debug the timestamps and activate the debug log of agenda (e.g. run your script with DEBUG=agenda:* node yourScript.ts)

from agenda.

xts-bit avatar xts-bit commented on June 2, 2024

@simllll i provided my code to you by email please check.

from agenda.

xts-bit avatar xts-bit commented on June 2, 2024

@simllll My code:

import express from 'express';
const router = express.Router();
import { MongoDBConnection } from './db.js'
import { Agenda } from '@hokify/agenda';
const connection = await MongoDBConnection();
const agenda = new Agenda({ mongo: connection });

function GetTime() {
    const currentTime = new Date();
    const newTime = new Date(currentTime.getTime() + 10000);

    return newTime;
}

agenda.define('ScheduleUserExpiration', async job => {
    await AgendaWorking(job.attrs.data.email);
});

(async function () {
    agenda
        .on('ready', () => console.log("Agenda started!"))
        .on('error', () => console.log("Agenda connection error!"));
    await agenda.start();
})();

router.post('/callagenda', async (req, res) => {
    const { email } = req.body;
    console.log(email)
    ScheduleUserExpiration(email);
    res.send("He")
})
agenda.on('start', job => {
    console.log(`Job ${job.attrs.name} started`);
});

agenda.on('complete', job => {
    console.log(`Job ${job.attrs.name} completed`);
});

agenda.on('fail', (err, job) => {
    console.log(`Job ${job.attrs.name} failed with error: ${err.message}`);
});

const ScheduleUserExpiration = async (email) => {

    const expirationTime = await GetTime(); 

    const jobData = {
        email: email,
    };

    const jobOptions = {
        maxAttempts: 3,
        backoff: '1s',
    };

    await agenda.schedule(expirationTime, 'ScheduleUserExpiration', jobData, jobOptions);
};

const AgendaWorking = async (email) => {
    console.log("Agenda Working", email)
}
export { router as Agenda };

db.js:

import mongoose from 'mongoose';
mongoose.set('strictQuery', false);

export const MongoDBConnection = async () => {
    try {
        await mongoose.connect('mongodb://localhost:27017/')
        console.log('Connected to database');
        return mongoose.connection;
    } catch (err) {
        console.log('Error connecting to database: ' + err);
    }
};

from agenda.

harisvsulaiman avatar harisvsulaiman commented on June 2, 2024

@xts-bit like @simllll said, we can't offer one on one support.

This is not a problem with the library. You should not be spamming us via email and issues.

You could ask in stack overflow or use this as a learning exercise or ask any one familiar with agenda for paid support.

That said you forgot an await in
ScheduleUserExpiration(email).

Locking this thread.

from agenda.

Related Issues (20)

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.