Giter Site home page Giter Site logo

Comments (15)

isocroft avatar isocroft commented on May 29, 2024

Please @endroca share the actual code of SendEmail job in your code-base. This will give better context on what is going wrong. Thanks

from adonis-queue.

endroca avatar endroca commented on May 29, 2024

Thank you, I updated the post

from adonis-queue.

isocroft avatar isocroft commented on May 29, 2024

Currently looked into it. I feel this might be because you are not calling the done(null, result) function inside the handle() method. I will inform @stitchng to update the README on this.

So, for now please update the handle() function of your SendEmail job to look like the below:

async handle(link, done) {
console.log(Job [${this.constructor.name}] - handler called: status=running; id=${this.id});

link.reportProgress(10);

let data = link.data; // arguments passed into the constructor
let error = null;
let result = null;

try {
  result = await Mail.send(data.emailTemplate, data.emailBody, message => {
    message.to(data.emailAddress);
    message.from(data.emailFrom);
    message.subject(data.emailSubject);
  });
  link.reportProgress(50);
} catch (err) {
  link.reportProgress(50);
  error = err;
  result = undefined
} finally {
  link.reportProgress(100);
}

return done(error, result);
}

And then, try again

Let me know the outcome of this please @endroca . Thank you

from adonis-queue.

endroca avatar endroca commented on May 29, 2024

The error continues =(

info: serving app on http://127.0.0.1:3333
@@adonisjs/Queue: [Redis] Queue [low] now ready
Job [SendEmail] - handler called: status=running; id=1
Job [SendEmail] - status:retrying; id=1  undefined
Job [SendEmail] - handler called: status=running; id=1
Job [SendEmail] - status:failed; id=1  undefined
info: @@adonis/Queue: removing job from queue...

I used the same function that you described

  async handle(link, done) {
    console.log(
      `Job [${this.constructor.name}] - handler called: status=running; id=${this.id}`
    );

    link.reportProgress(10);

    const { data } = link; // arguments passed into the constructor
    let error = null;
    let result = null;

    try {
      result = await Mail.send(data.emailTemplate, data.emailBody, message => {
        message.to(data.emailAddress);
        message.from(data.emailFrom);
        message.subject(data.emailSubject);
      });
      link.reportProgress(50);
    } catch (err) {
      link.reportProgress(50);
      error = err;
      result = undefined;
    } finally {
      link.reportProgress(100);
    }

    return done(error, result);
  }

The funny thing is that I get two emails, for the failure attempt

from adonis-queue.

stitchng avatar stitchng commented on May 29, 2024

@endroca Please can you update the handle function as below:

async handle(link, done) {
    console.log(
      `Job [${this.constructor.name}] - handler called: status=running; id=${this.id}`
    );

    link.reportProgress(10);

    const { data } = link; // arguments passed into the constructor
    let error = null;
    let result = null;

    try {
      result = await Mail.send(data.emailTemplate, data.emailBody, message => {
        message.to(data.emailAddress);
        message.from(data.emailFrom);
        message.subject(data.emailSubject);
      });
      link.reportProgress(50);
    } catch (err) {
      link.reportProgress(50);
      error = err;
      result = undefined;
    } finally {
      link.reportProgress(100);
      done(error, result);
    }
  }

It should be fine now

from adonis-queue.

endroca avatar endroca commented on May 29, 2024

I understand that with asynchronous call sending email it really makes sense to place the return function within the finally

    } finally {
      console.log('success');
      link.reportProgress(100);
      done(error, result);
    }
@@adonisjs/Queue: [Redis] Queue [low] now ready
Job [SendEmail] - handler called: status=running; id=1 
Job [SendEmail] - status:retrying; id=1  undefined
Job [SendEmail] - handler called: status=running; id=1 
Job [SendEmail] - status:failed; id=1  undefined
info: @@adonis/Queue: removing job from queue...
success
success

However, the system returns the error function even before calling the "done" function

from adonis-queue.

stitchng avatar stitchng commented on May 29, 2024

@endroca confirming from the bee-queue repo. The handle function needs to return a Promise. Also from the reportProgress() function returns a promise as well and needs to be "awaited".

See below:

async handle(link) {
    console.log(
      `Job [${this.constructor.name}] - handler called: status=running; id=${this.id}`
    );

    await link.reportProgress(10);

    const { data } = link; // arguments passed into the constructor
    let error = null;
    let result = null;

    try {
      result = await Mail.send(data.emailTemplate, data.emailBody, message => {
        message.to(data.emailAddress);
        message.from(data.emailFrom);
        message.subject(data.emailSubject);
      });
      await link.reportProgress(50);
    } catch (err) {
      error = err;
      result = undefined;
      await link.reportProgress(50);
    } finally {
      await link.reportProgress(100);
      return error === null ? Promise.resolve(result) : Promise.reject(error);
    }
  }

from adonis-queue.

stitchng avatar stitchng commented on May 29, 2024

@endroca have you tried the above ? any luck ?

from adonis-queue.

mavafaei avatar mavafaei commented on May 29, 2024

any luck

Hi @stitchng
I try this way and error continues.

from adonis-queue.

synergixe avatar synergixe commented on May 29, 2024

@stitchng @isocroft i think you need to update bee-queue dependency to the latest version and release a new version. The errors seem to be coming from the bee-queue library.

from adonis-queue.

afolabiabass avatar afolabiabass commented on May 29, 2024

Any solution here, having the same problem. For now I have stopped it sending the email more than once by setting retryCount to '0' if you set to 0 default value of 2 replaces it (This in itself is an issue)

from adonis-queue.

isocroft avatar isocroft commented on May 29, 2024

A new version of the adonis-queue library has just been released - v0.1.10 on NPM. @endroca @afolabiabass @mavafaei @stitchng

from adonis-queue.

synergixe avatar synergixe commented on May 29, 2024

@endroca @afolabiabass can you give feedback on the latest release please ? Do the errors still persist ?

from adonis-queue.

stitchng avatar stitchng commented on May 29, 2024

@mavafaei @afolabiabass @endroca how is the new version for adonis-queue (v0.1.10) working ? Still having errors ?

from adonis-queue.

isocroft avatar isocroft commented on May 29, 2024

Hello @endroca @mavafaei . Happy New Year to you all. Are you still experiencing these issues ? Please provide more info thanks

from adonis-queue.

Related Issues (12)

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.