/**
  * Test loading of the task
  * 
  * @return void
  * 
  * @test
  */
 public function testLoadTask()
 {
     //generate a random value to verify
     $_testValue = mt_rand();
     //create a task and check it's instantiated
     $_task = $this->_helper->createTask('test', array('test' => $_testValue));
     $this->assertInstanceOf('Lilmuckers_Queue_Model_Queue_Task', $_task, 'Check that the task object was instantiated');
     //ensure the store ID on the task is correct
     $this->assertEquals($_task->getStore()->getId(), Mage::app()->getStore()->getId(), 'Check that the store view id is set to the task');
     //ensure the data that was set is okay
     $this->assertEquals($_testValue, $_task->getTest());
 }
 /**
  * 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.
         }
     }
 }
Esempio n. 3
0
 /**
  * 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');
         }
     }
 }
 /**
  * Create a task for testing with
  * 
  * @param int    $randomFactor A random factor to add to the task data
  * @param string $task         The task to flag
  * 
  * @return Lilmuckers_Queue_Model_Queue_Task
  */
 protected function _getTask($randomFactor = self::DEFAULT_TASK_DATA, $task = 'test')
 {
     return $this->_helper->createTask($task, array('test' => $randomFactor));
 }
 /**
  * Create a task for testing with
  * 
  * @param int $randomFactor a random factor to add to the task data
  * 
  * @return Lilmuckers_Queue_Model_Queue_Task
  */
 protected function _getTask($randomFactor)
 {
     return $this->_helper->createTask('test', array('test' => $randomFactor));
 }