Current section
Files
Jump to
Current section
Files
lib/diffo/provider/components/process_status.ex
# SPDX-FileCopyrightText: 2025 diffo contributors <https://github.com/diffo-dev/diffo/graphs.contributors>
#
# SPDX-License-Identifier: MIT
defmodule Diffo.Provider.ProcessStatus do
@moduledoc """
Ash Resource for a TMF ProcessStatus
"""
use Ash.Resource,
otp_app: :diffo,
domain: Diffo.Provider,
data_layer: AshNeo4j.DataLayer,
extensions: [AshOutstanding.Resource, AshJason.Resource]
resource do
description "An Ash Resource for a TMF Process Status"
plural_name :processStatuses
end
code_interface do
define :create
define :update
define :destroy
end
neo4j do
relate [
{:instance, :STATUSES, :outgoing, :Instance}
]
end
jason do
pick [:code, :severity, :message, :parameterized_message, :timestamp]
customize fn result, record ->
result
|> Diffo.Util.suppress(:message)
|> Diffo.Util.suppress(:parameterized_message)
|> Diffo.Util.set(:timestamp, Diffo.Util.to_iso8601(record.timestamp))
end
rename parameterized_message: :parameterizedMessage, timestamp: :timeStamp
end
outstanding do
expect [:code, :severity, :message, :parameterized_message, :timestamp]
end
actions do
defaults [:read, :destroy]
create :create do
description "creates a process status related to an instance"
primary? true
accept [:code, :severity, :message, :parameterized_message]
argument :instance_id, :uuid
change manage_relationship(:instance_id, :instance, type: :append_and_remove)
change set_attribute(:timestamp, &DateTime.utc_now/0)
end
read :list do
description "lists all process statuses"
end
read :list_process_statuses_by_instance_id do
description "lists process statuses by instance id"
argument :instance_id, :uuid
filter expr(instance_id == ^arg(:instance_id))
end
update :update do
description "updates a process status, touching the timestamp"
accept [:code, :severity, :message, :parameterized_message]
change set_attribute(:timestamp, &DateTime.utc_now/0)
end
end
attributes do
uuid_primary_key :id do
description "a uuid4, unique to this process status, generated by default"
public? false
end
attribute :code, :string do
description "the code of this process status, this is a mandatory value"
allow_nil? false
public? true
end
attribute :severity, :atom do
description "the severity of this process status, this is a mandatory value"
allow_nil? false
public? true
constraints one_of: [:INFO, :WARN, :ERROR, :CRITICAL]
end
attribute :message, :string do
description "the message of this process status, this is a mandatory value"
allow_nil? false
public? true
end
attribute :parameterized_message, :map do
description "the parameterized message of this process status, this is an optional value"
allow_nil? true
public? true
end
attribute :timestamp, :utc_datetime_usec do
description "the timestamp of this process status, timestamp is create or last update"
allow_nil? false
end
end
relationships do
belongs_to :instance, Diffo.Provider.Instance do
description "the instance statused by this process status"
allow_nil? false
public? true
end
end
preparations do
prepare build(sort: [timestamp: :desc])
end
end