/** * * @param type $mode * @return type * */ public function setup(GearmanJob $job) { $params = json_decode($job->workload()); $mode = $params[0]; $packageId = $params[1]; $package = new Logic_Package($mode); try { $packagesArray = $package->getNewPackages(1, $packageId); } catch (Exception $exc) { throw new Exception("Could not get ready packages!", $exc->getCode(), $exc); } if (count($packagesArray) === 0) { throw new Exception('No packages found!'); } foreach ($packagesArray as $packageItem) { try { $package->loadPackage($packageItem); } catch (Exception $exc) { throw new Exception($exc->getMessage()); } $package->updatePackageStatus($packageItem['id'], WsPackageStatus::STATUS_READY); } }
public function sendAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); try { $this->_updateStatus(WsPackageStatus::STATUS_AWAITING); $this->_logicPackage->send($id); } catch (Exception $exc) { $this->_updateStatus(WsPackageStatus::STATUS_ERROR); $this->_helper->messenger()->error('Wystąpił błąd podczas próby wysyłki pakietu!' . $exc->getMessage()); $this->_logicPackage->packageError($id, array($exc->getMessage())); return $this->_helper->redirector('index'); } return $this->_helper->redirector('index'); }
/** * 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); }