Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions backend/lib/edgehog/campaigns/campaign/campaign.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ defmodule Edgehog.Campaigns.Campaign do
change Changes.StartExecution
end

update :increase_max_in_progress_operations do
require_atomic? false
argument :max_in_progress_operations, :integer

change Changes.IncreaseMaxInProgressOperations
end

destroy :destroy do
description "Deletes a Campaign"
primary? true
Expand Down Expand Up @@ -243,4 +250,11 @@ defmodule Edgehog.Campaigns.Campaign do
match_with: [tenant_id: :tenant_id]
end
end

pub_sub do
prefix "campaigns"
module EdgehogWeb.Endpoint

publish :increase_max_in_progress_operations, [[:id, "*"]]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# This file is part of Edgehog.
#
# Copyright 2026 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

defmodule Edgehog.Campaigns.Campaign.Changes.IncreaseMaxInProgressOperations do
@moduledoc """
Increases max_in_progress_operations of a campaign mechanism.
"""

use Ash.Resource.Change

@impl Ash.Resource.Change
def change(changeset, _opts, _context) do
max_in_progress_operations =
Ash.Changeset.get_argument(changeset, :max_in_progress_operations)

campaign_mechanism = changeset.data.campaign_mechanism

mechanism = %{
campaign_mechanism
| value:
Map.update(
campaign_mechanism.value,
:max_in_progress_operations,
campaign_mechanism.value.max_in_progress_operations,
fn _ -> max_in_progress_operations end
)
}

Ash.Changeset.change_attribute(changeset, :campaign_mechanism, mechanism)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentDelete.Executor do

defp handle_update(notification, state, data) do
case notification.payload.action.name do
:mark_as_timed_out -> handle_mark_as_timed_out(notification, data)
:pause -> handle_mark_as_paused(state, data)
_ -> :keep_state_and_data
:mark_as_timed_out ->
handle_mark_as_timed_out(notification, data)

:pause ->
handle_mark_as_paused(state, data)

:increase_max_in_progress_operations ->
handle_increase_max_in_progress_operations(notification, data)

_ ->
:keep_state_and_data
end
end

Expand All @@ -81,6 +89,15 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentDelete.Executor do
{:keep_state_and_data, actions}
end

defp handle_increase_max_in_progress_operations(notification, data) do
data = %{
data
| mechanism: notification.payload.data.campaign_mechanism.value
}

{:keep_state, data}
end

defp handle_destroy(notification, data) do
case notification.payload.action.name do
:destroy_and_gc -> handle_destroy_and_gc(notification, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentDeploy.Executor do

defp handle_update(notification, state, data) do
case notification.payload.action.name do
:maybe_run_ready_actions -> handle_maybe_run_ready_actions(notification, data)
:mark_as_timed_out -> handle_mark_as_timed_out(notification, data)
:pause -> handle_mark_as_paused(state, data)
_ -> :keep_state_and_data
:maybe_run_ready_actions ->
handle_maybe_run_ready_actions(notification, data)

:mark_as_timed_out ->
handle_mark_as_timed_out(notification, data)

:pause ->
handle_mark_as_paused(state, data)

:increase_max_in_progress_operations ->
handle_increase_max_in_progress_operations(notification, data)

_ ->
:keep_state_and_data
end
end

Expand Down Expand Up @@ -112,4 +122,13 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentDeploy.Executor do
# Ignore pause requests in non-pauseable states (terminal states, already pausing, etc.)
:keep_state_and_data
end

defp handle_increase_max_in_progress_operations(notification, data) do
data = %{
data
| mechanism: notification.payload.data.campaign_mechanism.value
}

{:keep_state, data}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentStart.Executor do

defp handle_update(notification, state, data) do
case notification.payload.action.name do
:maybe_run_ready_actions -> handle_maybe_run_ready_actions(notification, data)
:mark_as_timed_out -> handle_mark_as_timed_out(notification, data)
:pause -> handle_mark_as_paused(state, data)
_ -> :keep_state_and_data
:maybe_run_ready_actions ->
handle_maybe_run_ready_actions(notification, data)

:mark_as_timed_out ->
handle_mark_as_timed_out(notification, data)

:pause ->
handle_mark_as_paused(state, data)

:increase_max_in_progress_operations ->
handle_increase_max_in_progress_operations(notification, data)

_ ->
:keep_state_and_data
end
end

Expand Down Expand Up @@ -116,4 +126,13 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentStart.Executor do
# Ignore pause requests in non-pauseable states (terminal states, already pausing, etc.)
:keep_state_and_data
end

defp handle_increase_max_in_progress_operations(notification, data) do
data = %{
data
| mechanism: notification.payload.data.campaign_mechanism.value
}

{:keep_state, data}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,20 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentStop.Executor do

defp handle_update(notification, state, data) do
case notification.payload.action.name do
:maybe_run_ready_actions -> handle_maybe_run_ready_actions(notification, data)
:mark_as_timed_out -> handle_mark_as_timed_out(notification, data)
:pause -> handle_mark_as_paused(state, data)
_ -> :keep_state_and_data
:maybe_run_ready_actions ->
handle_maybe_run_ready_actions(notification, data)

:mark_as_timed_out ->
handle_mark_as_timed_out(notification, data)

:pause ->
handle_mark_as_paused(state, data)

:increase_max_in_progress_operations ->
handle_increase_max_in_progress_operations(notification, data)

_ ->
:keep_state_and_data
end
end

Expand Down Expand Up @@ -117,4 +127,13 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentStop.Executor do
# Ignore pause requests in non-pauseable states (terminal states, already pausing, etc.)
:keep_state_and_data
end

defp handle_increase_max_in_progress_operations(notification, data) do
data = %{
data
| mechanism: notification.payload.data.campaign_mechanism.value
}

{:keep_state, data}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentUpgrade.Executor do

defp handle_update(notification, state, data) do
case notification.payload.action.name do
:maybe_run_ready_actions -> handle_maybe_run_ready_actions(notification, data)
:mark_as_timed_out -> handle_mark_as_timed_out(notification, data)
:pause -> handle_mark_as_paused(state, data)
_ -> :keep_state_and_data
:maybe_run_ready_actions ->
handle_maybe_run_ready_actions(notification, data)

:mark_as_timed_out ->
handle_mark_as_timed_out(notification, data)

:pause ->
handle_mark_as_paused(state, data)

:increase_max_in_progress_operations ->
handle_increase_max_in_progress_operations(notification, data)

_ ->
:keep_state_and_data
end
end

Expand Down Expand Up @@ -136,4 +146,13 @@ defmodule Edgehog.Campaigns.CampaignMechanism.DeploymentUpgrade.Executor do
# Ignore pause requests in non-pauseable states (terminal states, already pausing, etc.)
:keep_state_and_data
end

defp handle_increase_max_in_progress_operations(notification, data) do
data = %{
data
| mechanism: notification.payload.data.campaign_mechanism.value
}

{:keep_state, data}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ defmodule Edgehog.Campaigns.CampaignMechanism.FirmwareUpgrade.Executor do

defp handle_update(notification, state, data) do
case notification.payload.action.name do
:update_status -> handle_update_status(notification, data)
:pause -> handle_mark_as_paused(state, data)
_ -> :keep_state_and_data
:update_status ->
handle_update_status(notification, data)

:pause ->
handle_mark_as_paused(state, data)

:increase_max_in_progress_operations ->
handle_increase_max_in_progress_operations(notification, data)

_ ->
:keep_state_and_data
end
end

Expand Down Expand Up @@ -119,4 +127,13 @@ defmodule Edgehog.Campaigns.CampaignMechanism.FirmwareUpgrade.Executor do
# Ignore pause requests in non-pauseable states (terminal states, already pausing, etc.)
:keep_state_and_data
end

defp handle_increase_max_in_progress_operations(notification, data) do
data = %{
data
| mechanism: notification.payload.data.campaign_mechanism.value
}

{:keep_state, data}
end
end
3 changes: 3 additions & 0 deletions backend/lib/edgehog/campaigns/campaigns.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ defmodule Edgehog.Campaigns do
relay_id_translations input: [target_group_ids: :device_group]
end

update Campaign, :increase_max_in_progress_operations, :increase_max_in_progress_operations

destroy Channel, :delete_channel, :destroy
end
end
Expand All @@ -116,6 +118,7 @@ defmodule Edgehog.Campaigns do
define :mark_campaign_successful, action: :mark_as_successful
define :pause_campaign, action: :pause
define :resume_campaign, action: :resume
define :increase_max_in_progress_operations, action: :increase_max_in_progress_operations
end

resource CampaignTarget do
Expand Down
Loading
Loading