forked from edgehog-device-manager/edgehog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip - message passing on resource readyness
- Loading branch information
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
backend/lib/edgehog/containers/container/changes/emit_if_new.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# This file is part of Edgehog. | ||
# | ||
# Copyright 2024 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.Containers.Container.Changes.EmitIfNew do | ||
@moduledoc false | ||
use Ash.Resource.Change | ||
|
||
alias Edgehog.PubSub | ||
|
||
@impl Ash.Resource.Change | ||
def change(changeset, _opts, _context) do | ||
container_deploy = changeset.data | ||
|
||
if container_deploy.state == :sent, | ||
do: | ||
Ash.Changeset.after_transaction(changeset, fn _changeset, result -> | ||
with {:ok, _} <- result do | ||
# publish the available container event for the deployment only if the | ||
# transaction succeds | ||
PubSub.publish!(:available_container, container_deploy) | ||
end | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# This file is part of Edgehog. | ||
# | ||
# Copyright 2024 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.Containers.Container.Checker do | ||
@moduledoc false | ||
use GenStateMachine, callback_mode: [:handle_event_function, :state_enter] | ||
|
||
alias Edgehog.PubSub | ||
|
||
@impl GenStateMachine | ||
def init(opts) do | ||
# Assumption: opts contains the image deployment to listen for events | ||
image_deployment = Keyword.fetch!(opts, :image_deployment) | ||
deployment = Keyword.fetch!(opts, :deployment) | ||
|
||
PubSub.subscribe_to_events_for(image_deployment) | ||
PubSub.subscribe_to_events_for(deployment) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/lib/edgehog/containers/image/changes/emit_if_new.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# This file is part of Edgehog. | ||
# | ||
# Copyright 2024 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.Containers.Image.Changes.EmitIfNew do | ||
@moduledoc false | ||
use Ash.Resource.Change | ||
|
||
alias Edgehog.PubSub | ||
|
||
@impl Ash.Resource.Change | ||
def change(changeset, _opts, _context) do | ||
image_deploy = changeset.data | ||
|
||
if image_deploy.state == :sent, | ||
do: | ||
Ash.Changeset.after_transaction(changeset, fn _changeset, result -> | ||
with {:ok, _} <- result do | ||
# publish the available image event for the deployment only if the | ||
# transaction succeds | ||
PubSub.publish!(:image_ready, image_deploy) | ||
end | ||
end) | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
backend/lib/edgehog/containers/release/deployment/checker.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# This file is part of Edgehog. | ||
# | ||
# Copyright 2024 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.Containers.Release.Deployment.Checker do | ||
@moduledoc false | ||
|
||
use GenStateMachine, callback_mode: [:handle_event_function, :state_enter] | ||
|
||
@impl GenStateMachine | ||
def init(opts) do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters