Triggering the start of a task from a CRON job I have a site setup which is for subscribers only. I have added a user expiry date field to the users section and everything is working perfectly on the front end in that I can restrict access to accounts that have already passed their expiry date. 

However I need to send notification emails to accounts that expire today or will expire in 7 days time.

I am using the mailer plugin in combination with a basic plugin I have made. I have setup a basic plugin with a controller which calls the following function from the plugins service:

public function sendNotificationEmail()
{
    //Create an EmailModel
    $email = new EmailModel;

    //Set the necessary attributes 
    $email-&gt;fromName = 'Joe Blogs';
    $email-&gt;fromEmail = 'joe.blogs@example.com';
    $email-&gt;subject     = 'Email subject';
    $email-&gt;htmlBody    = 'The message';


    //RecipientsModel
    $recipients = new Mailer_RecipientsModel();
    $recipients-&gt;recipients = array(
        array(
            'to' =&gt; 'jane.doe@example.com'
        )
    );

    if( $recipients-&gt;validate()){
        //Create mailer
        craft()-&gt;mailer_main-&gt;newMailer($recipients, $email); //This will start the MailerTask
    }


}


As you can see, at the moment I'm just sending a single test email each time. Everything works as expected but I've noticed that the task does not get triggered until I refresh the CP. This is a problem in my case, I think, because I want to trigger everything from a CRON job.

If anyone has any solution as to how to automatically trigger the task or if there are any alternative methods to solve this problem, I'd love to here them :)

btw, the reason I went down the task route was that the system could be sending to 100s of email addresses at a time and I didn't want to be (a) treated as spam or (b) get a timeout from the request
Everything you need to manage tasks is in the TasksService, so you should be able to just use that in your controller action to kick off any pending tasks, using something along the lines of:

if (!craft()-&gt;tasks-&gt;isTaskRunning())
{
    $task = craft()-&gt;tasks-&gt;getNextPendingTask();

    if ($task)
    {
        craft()-&gt;tasks-&gt;runPendingTasks();
    }
}


If you have a look around craft/app/services/TasksService.php you'll see you can also grab and run tasks by type which might be useful in this situation.