function shutdown() { if (Database::hasBeenUsed()) { Database::commit(); } // Jobs must not write to database! $queue = JobQueue::getInstance(); $jobs = $queue->executeJobs(); gfDebug("Request ended.\n"); }
public function output() { $jobs = JobQueue::getInstance(); if ($jobs->countJobs() > 0 && !$this->willCloseConnection) { gfDebug(__METHOD__ . " Forced close connection for background jobs."); $this->closeConnection(true); } $this->outputHttpHeaders(); $this->outputHttpBody(); if ($this->willCloseConnection) { @ini_set('zlib.output_compression', 'Off'); @apache_setenv('no-gzip', 1); header("Connection: close"); $outputSize = ob_get_length(); header("Content-Length: {$outputSize}"); } ob_end_flush(); ob_flush(); flush(); if ($this->willCloseConnection && session_id()) { session_write_close(); } }
protected function sendYourTurn() { if ($this->getSource() != 'app') { return; } /* * Hack: cannot pass $this to closures. * They are objects and define their * own $this. */ $ref = $this; $call = function () use($ref) { $sender = new AppPushSender($ref->getSourceId()); $sender->sendYourTurn($ref); }; $jobs = JobQueue::getInstance(); $jobs->addJob($call); }
public function create() { $this->created_at = new \DateTime(); $jq = JobQueue::getInstance(); $jq->add($this); }
public static function newFromTicket($ticket, $ts_time_out = null) { if (!$ts_time_out) { $ts_time_out = time(); } $ret = self::newRecord(); $ret->setCode($ticket->getCode()); $ret->setTimeIn($ticket->getTimeIn()); $ret->setSource($ticket->getSource()); if ($ticket->getTable() == 'ticket_in') { $ret->setTimeExec(null); $ret->setIsTrash(false); $ret->setTimeOut($ts_time_out); } else { global $gvTrashThreshold, $gvSessionTimeout; $ret->setOpCode($ticket->getOpCode()); $ret->setDeskNumber($ticket->getDeskNumber()); $ret->setTimeExec($ticket->getTimeExec()); if ($ts_time_out - $ticket->getTimeExec() > $gvSessionTimeout) { // Never set exec duration beyond sessionTimeout $ts_time_out = $ticket->getTimeExec() + $gvSessionTimeout; } $ret->setTimeOut($ts_time_out); if (in_array($ret->ts_source, array('app', 'web')) && $ret->ts_time_out - $ret->ts_time_exec < $gvTrashThreshold) { // This ticket is trash $ret->setIsTrash(true); Ban::recordTicketTrash($ticket); // Send trash notice (only for app) if ($ticket->getSource() == 'app') { $call = function () use($ticket) { $sender = new AppPushSender($ticket->getSourceId()); $sender->sendTrashNotice(); }; $jobs = JobQueue::getInstance(); $jobs->addJob($call); } } } return $ret; }