Skip to content

Commit

Permalink
Cancel automatic pending tasks that are removed during new assignments (
Browse files Browse the repository at this point in the history
#301)

* Cancel automatic pending tasks that are removed during new assignments

Signed-off-by: Aaron Chong <[email protected]>

* Lint

Signed-off-by: Aaron Chong <[email protected]>

* Use unordered_set

Signed-off-by: Aaron Chong <[email protected]>

---------

Signed-off-by: Aaron Chong <[email protected]>
(cherry picked from commit fb23496)
Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth committed Sep 28, 2023
1 parent 09d76b8 commit d7d2758
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rmf_fleet_adapter/src/rmf_fleet_adapter/TaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,29 @@ void TaskManager::set_queue(
{
return;
}

// Cancel pending automatic tasks that will be removed from the new
// assignments.
std::unordered_set<std::string> new_automatic_task_ids;
const std::vector<std::string> cancellation_labels =
{"New task assignments received."};
for (const auto& a : assignments)
{
if (a.request()->booking()->automatic())
{
new_automatic_task_ids.insert(a.request()->booking()->id());
}
}
for (const auto& a : _queue)
{
if (a.request()->booking()->automatic() &&
new_automatic_task_ids.find(a.request()->booking()->id()) ==
new_automatic_task_ids.end())
{
_publish_canceled_pending_task(a, cancellation_labels);
}
}

_queue = assignments;
_publish_task_queue();
}
Expand Down

0 comments on commit d7d2758

Please sign in to comment.