Ejemplo n.º 1
0
 /**
  * Realizuje wysyłkę wiadomości w pakiecie
  * @param GearmanJob $job
  */
 public function sendpackage(GearmanJob $job)
 {
     $params = json_decode($job->workload());
     list($mode, $packageDataId, $packageId) = $params;
     $package = new Logic_Package($mode);
     $wsPackage = new WsPackage();
     $wsPackageRow = $wsPackage->findOne($packageId);
     $package->updatePackageStatus($packageId, WsPackageStatus::STATUS_STARTED);
     $wsServiceSetRow = $wsPackageRow->findParentRow('WsServiceSet');
     $rawData = $package->getRawDataToSend($packageDataId);
     $client = Logic_Client::getInstanceByUser($package->getLastPackageStatus($packageId)->created_by);
     $package->updatePackageDataStatus($packageDataId, array('id_status' => WsPackageStatus::STATUS_STARTED));
     $service;
     switch ($mode) {
         case Logic_Package::SMS_MODE:
             $loadBalancer = $client->getLoadBalancer(Wsclient::GROUP_SMS, $wsServiceSetRow->ws_service_group_id);
             $hasErrors = false;
             $service = $loadBalancer->getService();
             do {
                 if (null === $service) {
                     $package->updatePackageDataStatus($packageDataId, array('id_status' => WsPackageStatus::STATUS_ERROR));
                     return $job->sendException("Unable to get service! Check backup service!");
                 }
                 $sms = new Logic_Sms($service, $wsPackageRow->ip, $wsServiceSetRow->id);
                 try {
                     if ($wsPackageRow->getLastStatus()->id_status == WsPackageStatus::STATUS_STARTED) {
                         $response = $sms->package($rawData, $packageId);
                         $package->updatePackageDataStatus($packageDataId, array('id_status' => WsPackageStatus::STATUS_SENT, 'external_package_id' => $response->packageId, 'ws_service_id' => $service->id));
                         $package->confirmPackageSend($wsPackageRow);
                     }
                     break;
                 } catch (Exception $exc) {
                     $hasErrors = true;
                     $package->updatePackageDataStatus($packageDataId, array('id_status' => WsPackageStatus::STATUS_ERROR));
                     $service = $loadBalancer->getService();
                     sleep(1);
                 }
             } while (true === $hasErrors || !(true === is_object($response) && true === property_exists($response, 'packageId')));
             break;
     }
     unset($client);
 }
Ejemplo n.º 2
0
 protected function _updateStatus($status)
 {
     $request = $this->getRequest();
     $id = $this->_helper->IdConvert->hexToStr($request->getParam('id'));
     $model = new WsPackage();
     try {
         $packageRow = $model->findOne($id)->updatePackageStatus($status);
         if ($status == WsPackageStatus::STATUS_CANCELLED) {
             $dataModel = new WsPackageData();
             $dataModel->changeStatusByPackage($id, WsPackageStatus::STATUS_CANCELLED);
         }
     } catch (Exception $exc) {
         $this->_helper->messenger()->error();
     }
     $this->_helper->messenger()->success();
     return $this->_helper->redirector('index');
 }
Ejemplo n.º 3
0
 /**
  * Pobiera rekord ostatniego statusu dla pakietu
  * @param type $idPackage
  * @return type
  * @throws Logic_Exception
  */
 public function getLastPackageStatus($idPackage)
 {
     $package = new WsPackage();
     $packageRow = $package->findOne($idPackage);
     if (null === $packageRow) {
         throw new Logic_Exception("Package with ID={$idPackage} not found!");
     }
     return $packageRow->getLastStatus();
 }