/** * Test to load the backend adapter * * @return void * * @test */ public function testLoadingBackendAdapter() { //get the backend adapter $_adapter = $this->_helper->getAdapter(); //assert that it's an instance of the adapter abstract $this->assertInstanceOf('Lilmuckers_Queue_Model_Adapter_Abstract', $_adapter, 'Check that a valid adapter is loaded'); }
/** * Watch script that will loop ad-infinitum * * @param array $queues Array of queues to watch * * @return void */ protected function _watch($queues) { //get the adapter object $_adapter = $this->_helper->getAdapter(); //start the infinite while loop while (true) { try { if ($_adapter->getRunInline()) { //the adapter is built to explicitly run itself. $_adapter->run($queues); } else { //watch the queue list $_task = $_adapter->getTask($queues); //this is to open any DB functions that may have been closed $_adapter->reopenDbConnection(); //flag the task as a worker so it instantiates the queue properly $_task->setIsWorker(); //run the task via the queue $_task->getQueue()->runTask($_task); } } catch (Lilmuckers_Queue_Model_Queue_Db_Exception $e) { //close the database connection //This is because the worker will be running for some time //and we want to make sure that we don't end up dying because //of the DB connection being closed $_adapter->closeDbConnection(); } catch (Lilmuckers_Queue_Model_Adapter_Timeout_Exception $e) { //timeout waiting for job, ignore. } } }
/** * Watch script that will loop ad-infinitum * * @param array $queues Array of queues to watch * * @return void */ protected function _watch($queues) { //get the adapter object $_adapter = $this->_helper->getAdapter(); $_conn = Mage::getSingleton('core/resource')->getConnection('core_write'); $_tmp_f = ONEPLUS_QUEUE_FILE_DIR . '/' . md5(serialize($queues)) . '.tmp'; //start the infinite while loop while (true) { if (in_array('stock', $queues)) { if (defined('ONEPLUS_SYNC_STOCK_LOCK_FILE')) { $syncText = file_get_contents(ONEPLUS_SYNC_STOCK_LOCK_FILE); if (false != $syncText && '' != trim($syncText)) { sleep(10); continue; } } } try { if ($_adapter->getRunInline()) { //the adapter is built to explicitly run itself. $_adapter->run($queues); } else { //watch the queue list file_put_contents($_tmp_f, sprintf("Create At: %s\n%s", @date('Y-m-d H:i:s'), var_export($queues, true))); $_task = $_adapter->getTask($queues); //this is to open any DB functions that may have been closed $_adapter->reopenDbConnection(); $_conn->getConnection(); //flag the task as a worker so it instantiates the queue properly $_task->setIsWorker(); //run the task via the queue $_task->getQueue()->runTask($_task); } } catch (Lilmuckers_Queue_Model_Queue_Db_Exception $e) { $_adapter->closeDbConnection(); $_conn->closeConnection(); Mage::log($e->getMessage(), null, 'queue_error.log'); } catch (Lilmuckers_Queue_Model_Adapter_Timeout_Exception $e) { $_adapter->closeDbConnection(); $_conn->closeConnection(); Mage::log($e->getMessage(), null, 'queue_error.log'); } catch (Pheanstalk_Exception_ServerException $e) { $_adapter->closeDbConnection(); $_conn->closeConnection(); Mage::log($e->getMessage(), null, 'queue_error.log'); } catch (Exception $e) { $_conn->closeConnection(); $_adapter->closeDbConnection(); Mage::log($e->getMessage(), null, 'queue_mysql_error.log'); } } }
/** * Setup function, initialise the helper object * * @return void */ protected function setUp() { $this->_helper = Mage::helper('lilqueue'); $this->_adapter = $this->_helper->getAdapter(); $this->_queue = $this->_helper->getQueue('unit_tests'); }