symbiote / silverstripe-queuedjobs

A module that provides interfaces for scheduling jobs for certain times.
BSD 3-Clause "New" or "Revised" License
57 stars 73 forks source link

NEW Send an email notification when a job is broken #436

Closed emteknetnz closed 3 months ago

emteknetnz commented 3 months ago

Issue https://github.com/symbiote/silverstripe-queuedjobs/issues/435

There is an email sent for 'stalled' jobs, however there is not an email sent for 'broken' jobs. There is existing logic to ensure that there is only a single notification sent, however no email is actually sent, instead the only notification goes to the logger. An inline comment says "email" so looks like the intention all along was to send an email.

Testing steps

Create a vanilla install of silverstripe/installer + this PR

_config/myemail.yml

---
Name: myemail
After:
  - '#project-emailconfig'
---
SilverStripe\Control\Email\Email:
  admin_email:
    admin-email@example.com: 'Admin-email'
# + something to setup mailhog / mailcatcher / etc

MyBrokenJob.php

<?php

use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJob;

class MyBrokenJob extends AbstractQueuedJob
{
    public function getTitle()
    {
        return 'My broken job';
    }

    public function getJobType() {
        return QueuedJob::QUEUED;
    }

    public function process()
    {
        throw new Exception('MY BROKEN JOB EXCEPTION');
    }
}

In admin/queuedjobs create a new 'My broken job'

In console: vendor/bin/sake dev/tasks/ProcessJobQueueTask vendor/bin/sake dev/tasks/CheckJobHealthTask

There should be an 'Broken job' email that was sent