Skip to content

Commit db16ef2

Browse files
committed
net/control/Protocol: add packet CANCEL_JOB
1 parent d43e5c9 commit db16ef2

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cm4all-workshop (7.2) unstable; urgency=low
44
* workshop: implement TERMINATE_CHILDREN for "translate" and "spawn"
55
* cron: support multiple CHILD_TAGs for TERMINATE_CHILDREN
66
* control: allow enabling/disabling Workshop partitions by name
7+
* control: add packet CANCEL_JOB
78

89
--
910

libcommon

src/Instance.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "cron/Partition.hxx"
1111
#include "spawn/Client.hxx"
1212
#include "util/SpanCast.hxx"
13+
#include "util/StringSplit.hxx"
1314

1415
#include <fmt/core.h>
1516

@@ -285,6 +286,16 @@ Instance::OnControlPacket(BengControl::Command command,
285286
if (is_privileged)
286287
ReloadState();
287288
break;
289+
290+
case Command::CANCEL_JOB:
291+
if (const auto [partition_name, job_id] = Split(ToStringView(payload), '\0');
292+
!job_id.empty()) {
293+
for (auto &i : partitions)
294+
if (partition_name == i.GetName())
295+
i.CancelJob(job_id);
296+
}
297+
298+
break;
288299
}
289300
}
290301

src/workshop/Operator.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ public:
113113
return job.plan_name;
114114
}
115115

116+
bool IsId(std::string_view id) const noexcept {
117+
return job.id == id;
118+
}
119+
116120
[[gnu::pure]]
117121
bool IsChildTag(std::string_view value) const noexcept;
118122

src/workshop/Partition.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public:
9191
queue.EnableAdmin();
9292
}
9393

94+
void CancelJob(std::string_view id) noexcept {
95+
workplace.CancelJob(id);
96+
}
97+
9498
void TerminateChildren(std::string_view child_tag) noexcept {
9599
workplace.CancelTag(child_tag);
96100
}

src/workshop/Workplace.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ WorkshopWorkplace::OnTimeout(WorkshopOperator *o) noexcept
113113
OnExit(o);
114114
}
115115

116+
void
117+
WorkshopWorkplace::CancelJob(std::string_view id) noexcept
118+
{
119+
const auto n = operators.remove_and_dispose_if([id](const auto &o){
120+
return o.IsId(id);
121+
}, [](auto *o) {
122+
o->Cancel();
123+
delete o;
124+
});
125+
126+
if (n > 0)
127+
exit_listener.OnChildProcessExit(-1);
128+
}
129+
116130
void
117131
WorkshopWorkplace::CancelTag(std::string_view tag) noexcept
118132
{

src/workshop/Workplace.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ public:
9999
void OnExit(WorkshopOperator *o) noexcept;
100100
void OnTimeout(WorkshopOperator *o) noexcept;
101101

102+
void CancelJob(std::string_view id) noexcept;
102103
void CancelTag(std::string_view tag) noexcept;
103104
};

0 commit comments

Comments
 (0)