peppeocchi / php-cron-scheduler

PHP cron job scheduler
MIT License
808 stars 143 forks source link

Unable to get log or email #67

Closed karneaud closed 5 years ago

karneaud commented 5 years ago

I have the following being executed on a cron job every minute

$scheduler = new GO\Scheduler([
    'email' => [
        'subject' => 'Hourly Email History From Attendee Scheduler',
        'from' => ADMIN_EMAIL,
        'body' => 'This is the daily visitors count',
        'transport' => $transport,
        'ignore_empty_output' => true,
    ]
]);

$scheduler->call(
  function($run, $per_minute, $trottle) use ($emailer, $logger) {
    if($emailer->sendAttendeeEmails($run, $per_minute, $trottle) == -1)
    {
      trigger_error(sprintf('These emails failed to send %s' , join(',', $emailer->get_failed())),  E_USER_WARNING);
    }

    echo "Total emails send {$emailer->get_sent()}";
    echo "{$logger->dump()}";
  },
  [
    $NUM_EMAIL_PER_RUN,
    $EMAILS_PER_MINUTE,
    $NUM_SECS_PAUSE_RUN
  ],
  'SchedulerEmail'
  )->at("*/2 * * * *")->output('run.log')->email([
    [
         'themegastore_admin@smsmail.net' => 'Admin Store'
    ],
    'themegastore@smsmail.net'
]);
// Let the scheduler execute jobs which are due.
$scheduler->run();

The above code uses SwiftMailer to execute batch emails every 2 minutes then email and save to a file. While the job runs as expected I get neither an email nor an output file

I'm running PHP 7.0.32 using 2.*

Is it that I cannot run both or is there something else I'm missing here

UPDATE

I'm able now get the logs but not the emails

peppeocchi commented 5 years ago

@karneaud I see the issue, the documentation is wrong you should provide your email addresses on a single array, so instead of

->email([
    [
         'themegastore_admin@smsmail.net' => 'Admin Store'
    ],
    'themegastore@smsmail.net'
]

it should be

->email([
     'themegastore_admin@smsmail.net' => 'Admin Store',
    'themegastore@smsmail.net'
]

Please let me know if that solves your issue.