Saturday, 6 May 2017

I get an error when I try to create scheduler job Node js

I get this error in console when I run a scheduler job in node js enter image description here

Even the job "eventQuestionnaireMail" run successfully.

scheduler 2017-05-07T01:06:19.903Z - [INFO] - Scheduler registered successfully'eventQuestionnaireMail' +6ms

This is the ts file event.ts:

    var __get3daysagoEvents = function ()
    {
    var today = __moment().utc().startOf("day").toDate();
    var ago3days = __moment().utc().subtract(8, 
  "days").startOf("day").toDate();
    //var ago3days = __moment().utc().subtract(1,"min");
    console.log('gggggggggggggggggggggggggg');
    console.log(JSON.stringify(today));
    console.log('gggggggggggggggggggggggggg');
    console.log('mmmmmmmmmmmmmmmmmmmmmmmmmm');
    console.log(JSON.stringify(ago3days));
    console.log('mmmmmmmmmmmmmmmmmmmmmmmmmmmm');
    var query =
        {
            attributes: ["id", "name", "themeId", "goalId", 
   "startDate", "endDate", "status", "userId", "attendees"],
            where: {
                endDate: {
                    $gte: ago3days,
                    $lt: today
                },
                //status: "BOOKED"
            }
        };

    return __eventDao.findAll(query);
    console.log('XXXXXXXXXXXXXXXXXXXXXXXXXXX');
    console.log(JSON.stringify(query));
    console.log('XXXXXXXXXXXXXXXXXXXXXXXXXXX');
    };

    var __sendQuestionnaireMail = async function(user, eventId)
    {
    // Send questionnaire email

    var emailParams =
        [
            {
                name: "ClientName",
                content: user.firstName + " " + user.lastName
            },
            {
                name: "ClientId",
                content: user.companyId

            }
        ];

    var templateName = 
    yemp.server.utilities.mailUtil.getQualifiedTemplateName(
        "client-questionnaire");

    var recipients = [];
    recipients.push({
        email: user.email,
        role: "CLIENT"
    });

    let info = await __notificationService.notifyByEmail(templateName, 
    null, emailParams, recipients);
    console.log('lllllllllllllllllllllllllllllllllllllllllll');
    console.log(JSON.stringify(emailParams, recipients));
    console.log('llllllllllllllllllllllllllllllllllllllllllll');
    };

     this.sendMailfor3DaysAgoEvents = function ()
     {
      __get3daysagoEvents().then(function (events , user)
     {
        if (Array.isArray(events) === false)
        {
            return;
            console.log('000000000000000000000000000000000000000');
            console.log(events);

            console.log('000000000000000000000000000000000000000');
            console.log(JSON.stringify(events));

            console.log('000000000000000000000000000000000000000');


        }
        for (let event of events)
        {

    console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv');

    console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv');

     console.log('vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv');

            __sendQuestionnaireMail(user, event.id).then(function ()
            {
                console.log('22222222222222222222222222222222222');
                console.log('22222222222222222222222222222222222');

                yemp.server.log.info(this,
                    "client questionnaire has been sent for the event 
      [" + event.id + "]");
            }).catch(function (error)
            {
                yemp.server.log.error(this, error);

      console.log('????????????????????????????????????????????');

      console.log('????????????????????????????????????????????');

             });
            }
          ;
        });
         };

This is the eventQuestionnaireMail.ts:

   "use strict";

    exports.class = function ()
    {
   var __schedule = require("node-schedule");
   var __configurationService = yemp.server.services.configuration;
   let __eventService = yemp.server.services.event;

   this.start = function ()
    {
    var emailQuestionnaireSchedulerRule = 




    __configurationService.getApplicationConfiguration("email 
     QuestionnaireSchedulerRule");
    __schedule.scheduleJob(emailQuestionnaireSchedulerRule, function 
    ()
     {
        yemp.server.log.debug("Background: Sending a client 
      questionnaire after 3 days of event starting day");
        __eventService.sendMailfor3DaysAgoEvents();
     });
     }
     };



via Afef Mokhtari

No comments:

Post a Comment