public function execute() { $startedAt = time(); $startedAt -= $startedAt % 60; $campaign = new Campaign($this->campaign); Defero::pushCampaign($campaign->id(), $startedAt, $this->startId, $this->endId); }
public function process($taskId, $campaignId, $startTime, $lastSent, $startId = null, $endId = null) { $this->resetPointer(); while ($data = $this->getBatch()) { Defero::pushMessageBatch($campaignId, $data); if (count($data) < $this->_batchSize) { // don't search for more if the last batch was not full break; } } }
public function execute() { $this->_logger->setInstanceName($this->instanceName); $this->_pidFile = new PidFile("", $this->instanceName); while (true) { $startedAt = time(); $startedAt -= $startedAt % 60; $collection = new RecordCollection(new Campaign()); if (!$collection->hasMappers()) { Log::warning('No mappers found'); } foreach ($collection as $campaign) { /** @var Campaign $campaign */ if ($campaign->isDue($startedAt)) { try { Defero::pushCampaign($campaign->id(), $startedAt); if (CronParser::isValid($campaign->sendAt)) { // check average sends on scheduled $avgEndDate = (new \DateTime())->setTimestamp($startedAt); $avgStartDate = CronParser::prevRun($campaign->sendAt, $avgEndDate); $avgEndDate->sub($avgStartDate->diff($avgEndDate)); $avgStartDate->setTime($avgStartDate->format('H') - 1, 0, 0); $latestStats = MailStatistic::getCampaignStats($campaign->id(), $avgStartDate, $avgEndDate); $diff = $avgStartDate->diff($avgEndDate); $diffLatest = max(1, intval($diff->format('%i')) + intval($diff->format('%h') * 60) + intval($diff->format('%d') * 3600)); $latestHourly = $latestStats->sent / $diffLatest * 60; if ($campaign->warnMin && $latestHourly < $campaign->warnMin || $campaign->warnMax && $latestHourly > $campaign->warnMax) { Log::warning('Sending outside threshold', ['campaign' => $campaign->id(), 'average' => $latestHourly, 'warnMin' => $campaign->warnMin, 'warnMax' => $campaign->warnMax]); } } } catch (\Exception $e) { Log::error('Campaign ' . $campaign->id() . ': ' . $e->getMessage() . ' (Line: ' . $e->getLine() . ')'); } } else { Log::debug('Campaign ' . $campaign->id() . ' not due'); } } $endTime = time(); $endTime -= $endTime % 60; if ($endTime == $startedAt) { sleep(30); } } }
public function renderSend($id) { $failMsg = 'Could not queue Campaign'; try { $pushed = Defero::pushCampaign($id); } catch (\Exception $e) { $pushed = false; $failMsg = $e->getMessage(); } if ($pushed) { return Redirect::to("/campaigns/{$id}")->with("msg", new TransportMessage("info", 'Campaign Queued')); } else { return Redirect::to("/campaigns/{$id}")->with("msg", new TransportMessage("error", $failMsg)); } }
public function execute() { $message = ['firstname' => 'tom', 'lastname' => 'kay', 'name' => 'tom kay', 'email' => '*****@*****.**', 'domain_id' => '3', 'user_id' => '22492349', 'currency' => '£']; Defero::pushMessage($this->campaignId, $message); }