Skip to content

Registered functions running immediately #1

Description

@IslandRhythms

I have a discord bot where one of the features is that on September 21st, it will send the youtube link the song "September". For some reason, these past two days it was running the task at noon. When trying to debug, it would also run on application restart. I'm wondering if there is an explanation to this behavior as I don't see why the code in its current state is allowing this behavior.

const db = require('../db');
const initTasks = require('@mongoosejs/task');

module.exports = async function tasks(bot) {
  try {
    const conn = await db().asPromise();
    const setup = { db: conn }
    initTasks(null, setup.db);
    const { Task } = setup.db.models;

    Task.registerHandler('september', function quirkMessage() {
      return september(bot);
    });

    await Task.startPolling();

    await Task.findOneAndUpdate({ name: 'september', status: 'pending' }, { scheduledAt: earthWindAndFire(), repeatAfterMS: millisecondsInYear }, { upsert: true, returnDocument: 'after' });

  } catch(error) {
    console.log('something went wrong registering all the handlers', error);
  }
}

function earthWindAndFire() {
  const date = new Date()
  const year = date.getFullYear();
  const septemberTwentyFirst = new Date(year, 8, 21, 19);
  return septemberTwentyFirst;
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions