| 1380 | } |
| 1381 | |
| 1382 | void taskHealthUpdated(const TaskHealthStatus& healthStatus) |
| 1383 | { |
| 1384 | if (state == DISCONNECTED) { |
| 1385 | VLOG(1) << "Ignoring task health update for task" |
| 1386 | << " '" << healthStatus.task_id() << "'," |
| 1387 | << " because the executor is not connected to the agent"; |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | // If the health checked container has already been waited on, |
| 1392 | // ignore the health update. This prevents us from sending |
| 1393 | // `TASK_RUNNING` after a terminal status update. |
| 1394 | if (!containers.contains(healthStatus.task_id())) { |
| 1395 | VLOG(1) << "Received task health update for terminated task" |
| 1396 | << " '" << healthStatus.task_id() << "'; ignoring"; |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | // If the health checked container has already been asked to |
| 1401 | // terminate, ignore the health update. |
| 1402 | // |
| 1403 | // TODO(alexr): Once we support `TASK_KILLING` in this executor, |
| 1404 | // consider sending health updates after sending `TASK_KILLING`. |
| 1405 | if (containers.at(healthStatus.task_id())->healthChecker.isNone()) { |
| 1406 | VLOG(1) << "Received task health update for terminating task" |
| 1407 | << " '" << healthStatus.task_id() << "'; ignoring"; |
| 1408 | return; |
| 1409 | } |
| 1410 | |
| 1411 | LOG(INFO) << "Received task health update for task" |
| 1412 | << " '" << healthStatus.task_id() << "', task is " |
| 1413 | << (healthStatus.healthy() ? "healthy" : "not healthy"); |
| 1414 | |
| 1415 | // Use the previous task status to preserve all attached information. |
| 1416 | // We always send a `TASK_RUNNING` right after the task is launched. |
| 1417 | CHECK_SOME(containers.at(healthStatus.task_id())->lastTaskStatus); |
| 1418 | const TaskStatus status = protobuf::createTaskStatus( |
| 1419 | containers.at(healthStatus.task_id())->lastTaskStatus.get(), |
| 1420 | id::UUID::random(), |
| 1421 | Clock::now().secs(), |
| 1422 | None(), |
| 1423 | None(), |
| 1424 | None(), |
| 1425 | TaskStatus::REASON_TASK_HEALTH_CHECK_STATUS_UPDATED, |
| 1426 | None(), |
| 1427 | healthStatus.healthy()); |
| 1428 | |
| 1429 | forward(status); |
| 1430 | |
| 1431 | if (healthStatus.kill_task()) { |
| 1432 | unhealthy = true; |
| 1433 | killTask(healthStatus.task_id()); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | private: |
| 1438 | // Use this helper to create a status update from scratch, i.e., without |