| 160 | } |
| 161 | |
| 162 | void QueueRunner::Run(Session* sess, const string& enqueue_op) { |
| 163 | bool first_iteration = true; |
| 164 | Status status; |
| 165 | while (status.ok()) { |
| 166 | if (coord_ && coord_->ShouldStop()) { |
| 167 | break; |
| 168 | } |
| 169 | status = RealRun(sess, enqueue_op, true); |
| 170 | if (first_iteration) { |
| 171 | if (!status.ok()) { |
| 172 | mutex_lock l(mu_); |
| 173 | enqueue_status_ = status; |
| 174 | } |
| 175 | counter_->DecrementCount(); |
| 176 | first_iteration = false; |
| 177 | } |
| 178 | } |
| 179 | bool last_run = false; |
| 180 | { |
| 181 | mutex_lock l(mu_); |
| 182 | runs_--; |
| 183 | last_run = (runs_ == 0); |
| 184 | } |
| 185 | |
| 186 | // Close the queue unless the coordinator is shutting down since the cancel op |
| 187 | // will be run anway in this case. |
| 188 | if (IsQueueClosed(status) && (!coord_ || !coord_->ShouldStop())) { |
| 189 | if (last_run && !close_op_name_.empty()) { |
| 190 | UpdateStatus(RealRun(sess, close_op_name_, false)); |
| 191 | } |
| 192 | } else if (!status.ok()) { |
| 193 | LOG(ERROR) << "Queue runner thread got a failure status: " |
| 194 | << status.ToString(); |
| 195 | UpdateStatus(status); |
| 196 | if (coord_) { |
| 197 | coord_->RequestStop().IgnoreError(); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | Status QueueRunner::GetStatus() { |
| 203 | mutex_lock l(mu_); |