diff --git a/lib/towerops/devices.ex b/lib/towerops/devices.ex index 4192a016..f400ca12 100644 --- a/lib/towerops/devices.ex +++ b/lib/towerops/devices.ex @@ -800,7 +800,19 @@ defmodule Towerops.Devices do _ = DeviceMonitorWorker.stop_monitoring(device.id) _ = DevicePollerWorker.stop_polling(device.id) - Repo.delete(device) + # Get agent assignment before deleting (if any) + assignment = Agents.get_device_assignment(device.id) + agent_token_id = if assignment, do: assignment.agent_token_id + + # Delete the device + result = Repo.delete(device) + + # Notify agent to stop processing jobs for this device + if agent_token_id do + Agents.broadcast_assignment_change(agent_token_id, :device_deleted) + end + + result end @doc """