private function sendEmail($subject, $html, User $user, $campaignId, $count)
 {
     $mailgun = $this->getContainer()->get('mailgun');
     $response = $mailgun->sendMessage(array('from' => '"Class Central\'s MOOC Tracker" <*****@*****.**>', 'to' => $user->getEmail(), 'subject' => $subject, 'html' => $html, 'o:campaign' => $campaignId));
     if (!($response && $response->http_response_code == 200)) {
         // Failed
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error");
     }
     return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Course New Session notification sent for {$count} courses to user with id {$user->getId()}");
 }
 private function sendEmail($subject, $html, User $user)
 {
     $mailgun = $this->getContainer()->get('mailgun');
     $response = $mailgun->sendMessage(array('from' => '"Dhawal Shah" <*****@*****.**>', 'to' => $user->getEmail(), 'subject' => $subject, 'html' => $html, 'o:campaign' => self::NEW_USER_FOLLOW_UP_CAMPAIGN_ID));
     if (!($response && $response->http_response_code == 200)) {
         // Failed
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error");
     }
     return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Email sent");
 }
 private function sendEmail($subject, $html, User $user, $campaignId, $deliveryTime)
 {
     $mailgun = $this->getContainer()->get('mailgun');
     $email = $user->getEmail();
     $env = $this->getContainer()->getParameter('kernel.environment');
     if ($env !== 'prod') {
         $email = $this->getContainer()->getParameter('test_email');
     }
     try {
         $response = $mailgun->sendMessage(array('from' => '"Class Central" <*****@*****.**>', 'to' => $email, 'subject' => $subject, 'html' => $html, 'o:campaign' => $campaignId, 'o:deliverytime' => $deliveryTime));
         if (!($response && $response->http_response_code == 200)) {
             // Failed
             return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error");
         }
     } catch (\Exception $e) {
         // Probably a email validation error
         // Failed
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, 'Mailgun Exception');
     }
     return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Email sent");
 }
 private function sendEmail($html, UserEntity $user, $numCourses, $campaignId, $deliveryTime)
 {
     $mailgun = $this->getContainer()->get('mailgun');
     $email = $user->getEmail();
     $env = $this->getContainer()->getParameter('kernel.environment');
     if ($env !== 'prod') {
         $email = $this->getContainer()->getParameter('test_email');
     }
     try {
         $response = $mailgun->sendMessage(array('from' => '"Class Central" <*****@*****.**>', 'to' => $email, 'subject' => $numCourses . ' brand new courses for you to join', 'html' => $html, 'o:campaign' => $campaignId, 'o:deliverytime' => $deliveryTime));
         if (!($response && $response->http_response_code == 200)) {
             // Failed
             return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error");
         }
     } catch (\Exception $e) {
         // Probably a email validation error
         // Failed
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, 'Mailgun Exception - ' . $e->getMessage());
     }
     return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Email sent for job " . self::NEW_COURSES_EMAIL_JOB_TYPE . " with user " . $user->getId());
 }
Beispiel #5
0
 /**
  * Runs a particular job
  * @param ESJob $job
  * @return SchedulerJobStatus
  */
 public function run(ESJob $job)
 {
     $logger = $this->getLogger();
     $class = $job->getClass();
     $jobId = $job->getId();
     $logger->info("RUNNER: Running job with id {$jobId}");
     // Check if the class exists
     if (!class_exists($job->getClass())) {
         $logger->error("Runner: Class {$class} not found for job with id {$jobId}", ESJob::getArrayFromObj($job));
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_CLASS_NOT_FOUND, "The class {$class} has not been found");
     }
     $task = new $class();
     $task->setContainer($this->container);
     $task->setJob($job);
     $task->setUp();
     $status = $task->perform(json_decode($job->getArgs(), true));
     $task->tearDown();
     $logger->info("RUNNER: Job with id {$jobId} completed", array('status' => SchedulerJobStatus::$statuses[$status->getStatus()], 'message' => $status->getMessage()));
     return $status;
 }