use async context more in health monitor

Push the async context into the HealthMonitor class implementation.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I465c9c839016416e683415dd235e69817b7e1ba6
diff --git a/health_monitor.cpp b/health_monitor.cpp
index b839ae7..0c732b0 100644
--- a/health_monitor.cpp
+++ b/health_monitor.cpp
@@ -10,12 +10,12 @@
 
 using namespace phosphor::health::utils;
 
-void HealthMonitor::create()
+auto HealthMonitor::startup() -> sdbusplus::async::task<>
 {
     info("Creating Health Monitor with config size {SIZE}", "SIZE",
          configs.size());
     constexpr auto BMCInventoryItem = "xyz.openbmc_project.Inventory.Item.Bmc";
-    auto bmcPaths = findPaths(bus, BMCInventoryItem);
+    auto bmcPaths = findPaths(ctx.get_bus(), BMCInventoryItem);
 
     for (auto& [type, collectionConfig] : configs)
     {
@@ -23,18 +23,24 @@
              std::to_underlying(type));
         collections[type] =
             std::make_unique<CollectionIntf::HealthMetricCollection>(
-                bus, type, collectionConfig, bmcPaths);
+                ctx.get_bus(), type, collectionConfig, bmcPaths);
     }
+
+    co_await run();
 }
 
-void HealthMonitor::run()
+auto HealthMonitor::run() -> sdbusplus::async::task<>
 {
     info("Running Health Monitor");
-    for (auto& [type, collection] : collections)
+    while (!ctx.stop_requested())
     {
-        debug("Reading Health Metric Collection for {TYPE}", "TYPE",
-              std::to_underlying(type));
-        collection->read();
+        for (auto& [type, collection] : collections)
+        {
+            debug("Reading Health Metric Collection for {TYPE}", "TYPE",
+                  std::to_underlying(type));
+            collection->read();
+        }
+        co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5));
     }
 }
 
@@ -50,17 +56,9 @@
     constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon";
 
     info("Creating health monitor");
-    HealthMonitor healthMonitor{ctx.get_bus()};
+    HealthMonitor healthMonitor{ctx};
     ctx.request_name(healthMonitorServiceName);
 
-    ctx.spawn([&]() -> sdbusplus::async::task<> {
-        while (!ctx.stop_requested())
-        {
-            healthMonitor.run();
-            co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5));
-        }
-    }());
-
     ctx.run();
     return 0;
 }