|
| 1 | +# |
| 2 | +# This file is part of Edgehog. |
| 3 | +# |
| 4 | +# Copyright 2026 SECO Mind Srl |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +# SPDX-License-Identifier: Apache-2.0 |
| 19 | +# |
| 20 | + |
| 21 | +defmodule Edgehog.Campaigns.Campaign.Changes.IncreaseMaxInProgressOperations do |
| 22 | + @moduledoc """ |
| 23 | + Increases max_in_progress_operations of a campaign mechanism. |
| 24 | + """ |
| 25 | + |
| 26 | + use Ash.Resource.Change |
| 27 | + |
| 28 | + @impl Ash.Resource.Change |
| 29 | + def change(changeset, _opts, _context) do |
| 30 | + max_in_progress_operations = |
| 31 | + Ash.Changeset.get_argument(changeset, :max_in_progress_operations) |
| 32 | + |
| 33 | + campaign_mechanism = changeset.data.campaign_mechanism |
| 34 | + |
| 35 | + mechanism = %{ |
| 36 | + campaign_mechanism |
| 37 | + | value: |
| 38 | + Map.update( |
| 39 | + campaign_mechanism.value, |
| 40 | + :max_in_progress_operations, |
| 41 | + campaign_mechanism.value.max_in_progress_operations, |
| 42 | + fn _ -> max_in_progress_operations end |
| 43 | + ) |
| 44 | + } |
| 45 | + |
| 46 | + Ash.Changeset.change_attribute(changeset, :campaign_mechanism, mechanism) |
| 47 | + end |
| 48 | +end |
0 commit comments