add dialyzer and fix id
All checks were successful
Build and Publish / build-release (push) Successful in 1m28s

This commit is contained in:
2026-04-21 14:26:37 -05:00
parent 2bf99bfb37
commit ca86980833
9 changed files with 158 additions and 29 deletions

View File

@@ -1,7 +1,8 @@
defmodule WorkloadService.Aggregates.QuoteTask do
use WorkloadService.Aggregates.Task,
task_type: "quote",
commands: WorkloadService.Commands.QuoteTask
commands: WorkloadService.Commands.QuoteTask,
submission_type: map()
def validate_submission(_) do
:ok

View File

@@ -1,7 +1,8 @@
defmodule WorkloadService.Aggregates.SolicitationTask do
use WorkloadService.Aggregates.Task,
task_type: "solicitation",
commands: WorkloadService.Commands.SolicitationTask
commands: WorkloadService.Commands.SolicitationTask,
submission_type: map()
def validate_submission(_) do
:ok

View File

@@ -8,24 +8,37 @@ defmodule WorkloadService.Aggregates.Task do
use WorkloadService.Aggregates.Task,
task_type: "quote"
end
"""
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t() | nil,
application_id: WorkloadService.Aggregates.ApplicationId.t() | nil,
task_info: map() | nil,
submission: map() | nil,
attachments: [String.t()],
status: String.t() | nil
}
## With custom submission type
defmodule QuoteTaskWithCustomSubmission do
defmodule CustomSubmission do
@type t :: %{...custom_fields: term()}
end
use WorkloadService.Aggregates.Task,
task_type: "quote",
submission_type: CustomSubmission.t()
end
"""
@callback validate_submission(map()) :: :ok | {:error, term()}
defmacro __using__(opts) do
task_type = Keyword.fetch!(opts, :task_type)
commands_module = Keyword.get(opts, :commands, WorkloadService.Commands.Task)
submission_type = Keyword.get(opts, :submission_type, quote(do: map()))
quote do
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t() | nil,
application_id: WorkloadService.Aggregates.ApplicationId.t() | nil,
task_info: map() | nil,
submission: unquote(submission_type) | nil,
attachments: [String.t()],
status: String.t() | nil
}
@behaviour Commanded.Aggregates.Aggregate
@task_type unquote(task_type)

View File

@@ -17,8 +17,8 @@ defmodule WorkloadService.Consumers.QuoteRequestedConsumer do
{:ok, conn} = AMQP.Connection.open(amqp_url())
{:ok, channel} = AMQP.Channel.open(conn)
AMQP.Queue.declare(channel, @queue, durable: true)
AMQP.Queue.bind(channel, @queue, @exchange, routing_key: @routing_key)
:ok = AMQP.Queue.declare(channel, @queue, durable: true)
:ok = AMQP.Queue.bind(channel, @queue, @exchange, routing_key: @routing_key)
{:ok, _tag} = AMQP.Basic.consume(channel, @queue)
Logger.info("QuoteRequestedConsumer started, listening on #{@queue}")
@@ -31,14 +31,15 @@ defmodule WorkloadService.Consumers.QuoteRequestedConsumer do
def handle_info({:basic_cancel_ok, _}, state), do: {:noreply, state}
def handle_info({:basic_deliver, payload, meta}, state) do
case process(payload) do
:ok ->
AMQP.Basic.ack(state.channel, meta.delivery_tag)
:ok =
case process(payload) do
:ok ->
AMQP.Basic.ack(state.channel, meta.delivery_tag)
{:error, reason} ->
Logger.error("QuoteRequestedConsumer: failed to process: #{inspect(reason)}")
AMQP.Basic.reject(state.channel, meta.delivery_tag, requeue: false)
end
{:error, reason} ->
Logger.error("QuoteRequestedConsumer: failed to process: #{inspect(reason)}")
AMQP.Basic.reject(state.channel, meta.delivery_tag, requeue: false)
end
{:noreply, state}
end

View File

@@ -6,12 +6,14 @@ defmodule WorkloadService.Release do
@app :workload_service
def migrate do
load_app()
init_event_store()
:ok = load_app()
:ok = init_event_store()
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
:ok
end
def rollback(repo, version) do
@@ -24,9 +26,10 @@ defmodule WorkloadService.Release do
end
defp load_app do
Application.ensure_all_started(:ssl)
Application.ensure_all_started(:postgrex)
Application.ensure_loaded(@app)
{:ok, _} = Application.ensure_all_started(:ssl)
{:ok, _} = Application.ensure_all_started(:postgrex)
:ok = Application.ensure_loaded(@app)
:ok
end
def init_event_store do
@@ -34,4 +37,4 @@ defmodule WorkloadService.Release do
:ok = EventStore.Tasks.Init.exec(config, [])
end
end
end