|
@@ -214,6 +214,14 @@ void WorkflowController::updateWorkflow(const httplib::Request& req, httplib::Re
|
|
|
|
|
|
|
|
// Note: updatedAt is managed by database automatically
|
|
// Note: updatedAt is managed by database automatically
|
|
|
|
|
|
|
|
|
|
+ // Remember the current run state so the reconciliation below can tell
|
|
|
|
|
+ // whether this update actually flipped it.
|
|
|
|
|
+ bool was_active = false;
|
|
|
|
|
+ auto before = storage_.get("workflows", id);
|
|
|
|
|
+ if (before.ok()) {
|
|
|
|
|
+ was_active = before.value().value("active", false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
auto result = storage_.update("workflows", id, body, 0, true);
|
|
auto result = storage_.update("workflows", id, body, 0, true);
|
|
|
if (result.failed()) {
|
|
if (result.failed()) {
|
|
|
sendError(res, result.error().message(), 404);
|
|
sendError(res, result.error().message(), 404);
|
|
@@ -223,9 +231,17 @@ void WorkflowController::updateWorkflow(const httplib::Request& req, httplib::Re
|
|
|
// Get updated workflow
|
|
// Get updated workflow
|
|
|
auto workflow = storage_.get("workflows", id);
|
|
auto workflow = storage_.get("workflows", id);
|
|
|
if (workflow.ok()) {
|
|
if (workflow.ok()) {
|
|
|
- // If workflow is active, update scheduler registration
|
|
|
|
|
- if (workflow.value().value("active", false)) {
|
|
|
|
|
- updateScheduledTriggers(id, true);
|
|
|
|
|
|
|
+ // Reconcile the scheduler in both directions. Registering on active
|
|
|
|
|
+ // but never unregistering on inactive let the stored flag and the
|
|
|
|
|
+ // scheduler drift apart, leaving a deactivated workflow still firing.
|
|
|
|
|
+ const bool is_active = workflow.value().value("active", false);
|
|
|
|
|
+ updateScheduledTriggers(id, is_active);
|
|
|
|
|
+
|
|
|
|
|
+ // Emit the same lifecycle events as the activate/deactivate endpoints,
|
|
|
|
|
+ // so a client updating the flag this way is not invisible to listeners.
|
|
|
|
|
+ if (is_active != was_active) {
|
|
|
|
|
+ ws_server_.broadcast(is_active ? "workflows.activated" : "workflows.deactivated",
|
|
|
|
|
+ {{"id", id}});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ws_server_.broadcast("workflows.updated", workflow.value());
|
|
ws_server_.broadcast("workflows.updated", workflow.value());
|