コード例 #1
0
 public function attemptUpdatingRowAsProcessing(Dunagan_ProcessQueue_Model_Task_Interface $taskObject)
 {
     $task_id = $taskObject->getId();
     if (empty($task_id)) {
         // $taskObject must be an existing/loaded object in order to lock it
         return false;
     }
     // Status here can be PENDING or ERROR
     $current_status = $taskObject->getStatus();
     if (Dunagan_ProcessQueue_Model_Task::STATUS_PROCESSING == $current_status) {
         // Assume another execution thread is actively processing this task
         return false;
     }
     $current_gmt_datetime = Mage::getSingleton('core/date')->gmtDate();
     // First, attempt to update the row based on id and status. If no rows are updated, another thread has already
     //  begun processing this row. Also we want to do this outside of any transactions so that we know other mysql
     //  connections will see that this row is already processing
     $update_bind_array = array('status' => Dunagan_ProcessQueue_Model_Task::STATUS_PROCESSING, 'status_message' => null, 'last_executed_at' => $current_gmt_datetime);
     $where_conditions_array = array('task_id=?' => $task_id, 'status=?' => $current_status, 'status<>?', Dunagan_ProcessQueue_Model_Task::STATUS_PROCESSING);
     $rows_updated = $this->_getWriteAdapter()->update($this->getMainTable(), $update_bind_array, $where_conditions_array);
     return $rows_updated;
 }