public function addAction() { $form = new $this->_addForm(); if ($this->getRequest()->isPost()) { if ($form->isCancelled($this->getRequest()->getPost())) { $this->_helper->messenger->info("Anulowano proces"); return $this->_helper->redirector('index'); } else { if ($form->isValid($this->getRequest()->getPost())) { $post = $form->getValues(); $fileName = $form->getReceivedFiles(); try { $packageId = $this->_logicPackage->createPackageFromFile($fileName['addressbook_import_csv'], $post['ws_service_set_id'], $post['name']); } catch (Logic_Exception $e) { return $this->_helper->messenger->error(); } $gearmanClient = new Logic_Gearman_Client(); try { $idHandler = $gearmanClient->setup($this->_logicPackage->getMode(), $packageId); $this->_logicPackage->setPackageJobHandler($packageId, $idHandler); } catch (Exception $exc) { return $this->_helper->messenger->error($exc->getMessage()); } $this->_helper->messenger->success("Zaimportowano pomyślnie"); if (isset($post['save_send']) && $post['save_send'] == '1') { return $this->_helper->redirector('send'); } return $this->_helper->redirector('index'); } } } $this->view->form = $form; }
public function __construct() { if (false === self::$_client instanceof GearmanClient) { self::$_client = new GearmanClient(); $this->_setupGearmanClient(); } }
/** * Wysłanie żądania wykonania wysyłki do GearmanWorker * @param integer $packageId Identyfikator pakietu * @param boolean $singleSend Czy wysyłka ma być realizowana z pominieciem funkcji masowej wysyłki. */ public function send($packageId, $singleSend = false) { $packageModel = new WsPackageData(); $select = $packageModel->select()->from('ws.package_data', array('id'))->where('ws_package_id=?', $packageId)->where('id_status=?', WsPackageStatus::STATUS_READY)->order('id ASC'); $packageDataRowset = $packageModel->fetchAll($select); switch ($this->getMode()) { case Logic_Package::SMS_MODE: $gearmanClient = new Logic_Gearman_Client(); // $gearmanClient = new Logic_Gearman_Worker_Send(); foreach ($packageDataRowset as $packageDataRow) { $jobHandler = $gearmanClient->sendpackage(Logic_Package::SMS_MODE, $packageDataRow->id, $packageId); if (null == $jobHandler || '' == $jobHandler) { $msg = "Cannot fetch job handler from Gerrit Worker!"; $this->updatePackageDataStatus($packageDataRow->id, array('id_status' => WsPackageStatus::STATUS_ERROR)); $this->packageError($packageId, array($msg)); throw new Exception($msg); } $this->updatePackageDataStatus($packageDataRow->id, array('id_job_handle' => $jobHandler)); } break; case Logic_Package::MAIL_MODE: break; default: $this->_logger->err("Niepoprawny typ pakietów. Oczekiwane to sms lub mail, podano: {$mode}"); } }