summaryrefslogtreecommitdiff
path: root/redfish-core/lib/task.hpp
diff options
context:
space:
mode:
authorJames Feist <james.feist@linux.intel.com>2020-05-19 23:48:07 +0300
committerJames Feist <james.feist@linux.intel.com>2020-05-28 21:02:31 +0300
commitfd9ab9e1cfca7b9fb31eb6d29b4468fdb0f515de (patch)
tree41f94806bc5f3632100ba075a455ef8e1c09792d /redfish-core/lib/task.hpp
parentac1ba02ad7a8479d1ef84fa3feeba98e8cd17a7f (diff)
downloadbmcweb-fd9ab9e1cfca7b9fb31eb6d29b4468fdb0f515de.tar.xz
FW Update: Task: Update messages
This adds reporting of percent updated and changes "staged" to paused to indicate some further action must happen to change state to Completed. Tested: validator passed "Messages": [ { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has started.", "MessageArgs": [ "2" ], "MessageId": "TaskEvent.1.0.1.TaskStarted", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 5 percent complete.", "MessageArgs": [ "2", 5 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 10 percent complete.", "MessageArgs": [ "2", 10 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 15 percent complete.", "MessageArgs": [ "2", 15 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 20 percent complete.", "MessageArgs": [ "2", 20 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 25 percent complete.", "MessageArgs": [ "2", 25 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 30 percent complete.", "MessageArgs": [ "2", 30 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 35 percent complete.", "MessageArgs": [ "2", 35 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 40 percent complete.", "MessageArgs": [ "2", 40 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 45 percent complete.", "MessageArgs": [ "2", 45 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 50 percent complete.", "MessageArgs": [ "2", 50 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 55 percent complete.", "MessageArgs": [ "2", 55 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 60 percent complete.", "MessageArgs": [ "2", 60 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 65 percent complete.", "MessageArgs": [ "2", 65 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 70 percent complete.", "MessageArgs": [ "2", 70 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 75 percent complete.", "MessageArgs": [ "2", 75 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 80 percent complete.", "MessageArgs": [ "2", 80 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 85 percent complete.", "MessageArgs": [ "2", 85 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 90 percent complete.", "MessageArgs": [ "2", 90 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 95 percent complete.", "MessageArgs": [ "2", 95 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has changed to progress 100 percent complete.", "MessageArgs": [ "2", 100 ], "MessageId": "TaskEvent.1.0.1.TaskProgressChanged", "Resolution": "None.", "Severity": "OK" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has been paused.", "MessageArgs": [ "2" ], "MessageId": "TaskEvent.1.0.1.TaskPaused", "Resolution": "None.", "Severity": "Warning" }, { "@odata.type": "#Message.v1_0_0.Message", "Message": "The task with id 2 has Completed.", "MessageArgs": [ "2" ], "MessageId": "TaskEvent.1.0.1.TaskCompletedOK", "Resolution": "None.", "Severity": "OK" } ], Change-Id: I32103e53486d459fe945a8b451d2092232c12e83 Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'redfish-core/lib/task.hpp')
-rw-r--r--redfish-core/lib/task.hpp52
1 files changed, 31 insertions, 21 deletions
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp
index cbae67b109..a746239a35 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -168,28 +168,8 @@ struct TaskData : std::enable_shared_from_this<TaskData>
std::chrono::system_clock::now());
}
- void startTimer(const std::chrono::seconds &timeout)
+ void extendTimer(const std::chrono::seconds &timeout)
{
- match = std::make_unique<sdbusplus::bus::match::match>(
- static_cast<sdbusplus::bus::bus &>(*crow::connections::systemBus),
- matchStr,
- [self = shared_from_this()](sdbusplus::message::message &message) {
- boost::system::error_code ec;
-
- // callback to return True if callback is done, callback needs
- // to update status itself if needed
- if (self->callback(ec, message, self) == task::completed)
- {
- self->timer.cancel();
- self->finishTask();
-
- // reset the match after the callback was successful
- boost::asio::post(
- crow::connections::systemBus->get_io_context(),
- [self] { self->match.reset(); });
- return;
- }
- });
timer.expires_after(timeout);
timer.async_wait(
[self = shared_from_this()](boost::system::error_code ec) {
@@ -211,6 +191,36 @@ struct TaskData : std::enable_shared_from_this<TaskData>
messages::taskAborted(std::to_string(self->index)));
self->callback(ec, msg, self);
});
+ }
+
+ void startTimer(const std::chrono::seconds &timeout)
+ {
+ if (match)
+ {
+ return;
+ }
+ match = std::make_unique<sdbusplus::bus::match::match>(
+ static_cast<sdbusplus::bus::bus &>(*crow::connections::systemBus),
+ matchStr,
+ [self = shared_from_this()](sdbusplus::message::message &message) {
+ boost::system::error_code ec;
+
+ // callback to return True if callback is done, callback needs
+ // to update status itself if needed
+ if (self->callback(ec, message, self) == task::completed)
+ {
+ self->timer.cancel();
+ self->finishTask();
+
+ // reset the match after the callback was successful
+ boost::asio::post(
+ crow::connections::systemBus->get_io_context(),
+ [self] { self->match.reset(); });
+ return;
+ }
+ });
+
+ extendTimer(timeout);
messages.emplace_back(messages::taskStarted(std::to_string(index)));
}