Announcement

Collapse
No announcement yet.

Duplicate emails sent from Workflows

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Duplicate emails sent from Workflows

    Problem: every Workflow sendEmail fire generates multiple emails being sent. Clients receive up to several dozens emails at once when there should be only 1.

    It started when we added a custom extension to crm/custom/Espo/Custom/Modules/Advanced/Core/Workflow/Actions/SendEmail.php and changed "From" field in all workflows to a custom parameter that is not a valid email. The new "SendEmail.php" is basically all the parents' functons and a simple script that inserts a value from a field in a linked Opportunity to a "From" field. It's only 20 rows so I can paste it here if you need it.

    It must have slowed down the whole sending-email-from-workflow sequence. So my guess is that when workflow does not get a success response in a limited period of time, it restarts from scratch, and that's how multiple actions are generated. The question is - how to stop it without reverting custom SendEmail.php? We may develop the same function some other way, but ultimately we need it.

    Additional info:

    The CRM version is still 4.8.2, Advanced Pack is 1.24.0 We understand that an update may fix the issue, but it takes time, so we are in search of a quicker fix.

    In CRM logs there are multiple rows like this:
    [2018-05-29 12:07:18] Espo.ERROR: CronManager: Failed job running, job [5b090c90a0178f203]. Error Details: Workflow[590b1c7551cbd7ed6]: Action failed [sendEmail] with cid [0]. [] [] with different job and workflow ids.

    `php /var/www/html/crm/cron.php` returns nothing

    There are a lot of Pending jobs in the past, but my guess it's a consequence rather than a reason. Duplicate emails appeared several days ago, while jobs started to get stuck yesterday - I think too many of them start to be created and retried so they don't have time to be executed and get stuck.

    Please help!

  • #2
    By the way, the custom extension-script itself works - it was tested with different workflows and different parameters, and clients received emails with different "From" fields. Now multiple emails are sent even with workflows that participated in the initial test, so the problem is cumulative.

    Comment


    • #3
      How much of emails. 3? If 3 per a single workflow trigger it can mean that the sedning job failed (didn't get responce from SMTP) and re-attempted.
      Last edited by yuri; 05-29-2018, 03:16 PM.

      Comment


      • #4
        In https://github.com/espocrm/espocrm/b...es/Job.php#L53 you can set $entity->set('attempts', 0);
        As it's set in newer versions by default.

        Comment


        • #5
          There can be dozens of them. But it's the triggers which are multiplied in the first place, so may be it's < 3 emails per trigger.

          E.g. there is a workflow that triggers a sequential workflow that sends an email, when an Entity is saved. I can see in the logs that the initial workflow is triggered only once (as intended), but the second runs already 10+ times.

          As far as I can see it happens only with workflows with SendEmail action inside

          I will try your solution and update on the results

          Comment


          • #6
            Not sure what it is. Could be a looping?

            Comment


            • #7
              By the way - shouldn't attempts be fired in different times? Like with a 2-hour pause between them? In our case multiple emails are fired at once or within 1-2 minutes max.

              Comment


              • #8
                >Could be a looping?

                It could. I will double check it, but it is still strange that looping strikes in all the workflows and not in only one that is faulty

                Comment


                • #9
                  On a second thought - it can't be a looping, since the Workflow #2 is Sequential and can never be triggered without a corresponding trigger from Workflow #1. But there is only one event for Workflow #1 and multiple for Workflow #2 in the logs. No other workflows are linked to #2. But I will still double check it

                  Comment


                  • #10
                    It's fired the next minute. It was. Now we disabled re-run.

                    Comment


                    • #11
                      After I set $attempts to 0 and removed all Pending workflows in the past and in the following 3 days (>25k), no new workflows get stuck and duplicated. Thanks for your help!

                      Comment

                      Working...
                      X