public function calc() { Billrun_Factory::log()->log("Execute reset", Zend_Log::INFO); $rebalance_queue = Billrun_Factory::db()->rebalance_queueCollection(); $limit = Billrun_Config::getInstance()->getConfigValue('resetlines.limit', 10); $offset = Billrun_Config::getInstance()->getConfigValue('resetlines.offset', '1 hour'); $query = array('creation_date' => array('$lt' => new MongoDate(strtotime($offset . ' ago')))); $sort = array('creation_date' => 1); $results = $rebalance_queue->find($query)->sort($sort)->limit($limit); $billruns = array(); $all_sids = array(); foreach ($results as $result) { $billruns[$result['billrun_key']][] = $result['sid']; $all_sids[] = $result['sid']; } foreach ($billruns as $billrun_key => $sids) { $model = new ResetLinesModel($sids, $billrun_key); try { $ret = $model->reset(); if (isset($ret['err']) && !is_null($ret['err'])) { return FALSE; } $rebalance_queue->remove(array('sid' => array('$in' => $sids))); } catch (Exception $exc) { Billrun_Factory::log()->log('Error resetting sids ' . implode(',', $sids) . ' of billrun ' . $billrun_key . '. Error was ' . $exc->getTraceAsString(), Zend_Log::ALERT); return $this->setError($exc->getTraceAsString(), array('sids' => $sids, 'billrun_key' => $billrun_key)); } } Billrun_Factory::log()->log("Success resetting sids " . implode(',', $all_sids), Zend_Log::INFO); return true; }
public function __construct($sids, $billrun_key) { $this->sids = $sids; $this->billrun_key = strval($billrun_key); $this->process_time_offset = Billrun_Config::getInstance()->getConfigValue('resetlines.process_time_offset', '15 minutes'); }
/** * method to retrieve the config instance * * @return Billrun_Config */ public static function config() { if (!self::$config) { self::$config = Billrun_Config::getInstance(); } return self::$config; }
/** * Updates the billrun costs, lines & breakdown with the input line if the line is not already included in it * @param string $billrun_key the billrun_key to insert into the billrun * @param array $counters keys - usage type. values - amount of usage. Currently supports only arrays of one element * @param array $pricingData the output array from updateSubscriberBalance function * @param Mongodloid_Entity $row the input line * @param boolean $vatable is the line vatable or not * @return Mongodloid_Entity the billrun doc of the line, false if no such billrun exists */ public function updateBillrun($billrun_key, $counters, $pricingData, $row, $vatable) { $sid = $row['sid']; $sraw = $this->getSubRawData($sid); if ($sraw) { // it could be that this sid hasn't been returned on active_subscribers... $this->addLineToSubscriber($counters, $row, $pricingData, $vatable, $billrun_key, $sraw); $this->updateCosts($pricingData, $row, $vatable, $sraw); $this->setSubRawData($sraw); } else { Billrun_Factory::log("Subscriber {$sid} is not active, yet has lines", Zend_log::ALERT); $subscriber_general_settings = Billrun_Config::getInstance()->getConfigValue('subscriber', array()); $null_subscriber_params = array('data' => array('aid' => $row['aid'], 'sid' => $sid, 'plan' => null, 'next_plan' => null)); $subscriber_settings = array_merge($subscriber_general_settings, $null_subscriber_params); $subscriber = Billrun_Subscriber::getInstance($subscriber_settings); $this->addSubscriber($subscriber, "closed"); $this->updateBillrun($billrun_key, $counters, $pricingData, $row, $vatable); } }