Skip to content
Closed
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
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config :git_hooks, auto_install: false
# To enable verbose logging during debugging, set LOG_LEVEL env var:
# LOG_LEVEL=debug mix test test/my_test.exs
#
log_level = System.get_env("LOG_LEVEL", "debug") |> String.to_existing_atom()
log_level = System.get_env("LOG_LEVEL", "warning") |> String.to_existing_atom()

config :logger,
level: log_level,
Expand Down
16 changes: 8 additions & 8 deletions lib/jido/agent/directive/cron.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ defmodule Jido.Agent.Directive.Cron do
%Cron{cron: "*/5 * * * *", message: check_signal, job_id: :check, timezone: "America/New_York"}
"""

require Logger

alias Jido.AgentServer
alias Jido.AgentServer.CronRuntimeSpec
alias Jido.Log

@schema Zoi.struct(
__MODULE__,
Expand Down Expand Up @@ -70,9 +69,9 @@ defmodule Jido.Agent.Directive.Cron do
{:ok, pid} <- AgentServer.start_runtime_cron_job(state, logical_id, runtime_spec),
{:ok, persisted_state} <-
persist_then_commit_registration(state, pid, logical_id, cron_spec, runtime_spec) do
Logger.debug(
"AgentServer #{agent_id} registered cron job #{inspect(logical_id)}: #{cron_expr}"
)
Log.debug(fn ->
"AgentServer #{agent_id} registered cron job #{Log.safe_inspect(logical_id)}: #{cron_expr}"
end)

AgentServer.emit_cron_telemetry_event(persisted_state, :register, %{
job_id: logical_id,
Expand All @@ -82,9 +81,10 @@ defmodule Jido.Agent.Directive.Cron do
{:ok, persisted_state}
else
{:error, reason} ->
Logger.error(
"AgentServer #{agent_id} failed to register cron job #{inspect(logical_id)}: #{inspect(reason)}"
)
Log.error(fn ->
"AgentServer #{agent_id} failed to register cron job #{Log.safe_inspect(logical_id)}: " <>
Log.safe_inspect(reason)
end)

{:ok, handle_failed_registration(state, logical_id, on_failure)}
end
Expand Down
20 changes: 12 additions & 8 deletions lib/jido/agent/directive/cron_cancel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
defimpl Jido.AgentServer.DirectiveExec, for: Jido.Agent.Directive.CronCancel do
@moduledoc false

require Logger
alias Jido.Log
alias Jido.AgentServer.State

def exec(%{job_id: logical_id}, _input_signal, state) do
Expand All @@ -44,7 +44,9 @@ defimpl Jido.AgentServer.DirectiveExec, for: Jido.Agent.Directive.CronCancel do

new_state = %{runtime_state | cron_specs: proposed_specs}

Logger.debug("AgentServer #{agent_id} cancelled cron job #{inspect(logical_id)}")
Log.debug(fn ->
"AgentServer #{agent_id} cancelled cron job #{Log.safe_inspect(logical_id)}"
end)

emit_telemetry(new_state, :cancel, %{job_id: logical_id})
{:ok, new_state}
Expand All @@ -53,9 +55,10 @@ defimpl Jido.AgentServer.DirectiveExec, for: Jido.Agent.Directive.CronCancel do
{_pid, runtime_state} = drop_runtime_job(state, logical_id)
new_state = %{runtime_state | cron_specs: proposed_specs}

Logger.error(
"AgentServer #{agent_id} failed to persist cron cancellation for #{inspect(logical_id)}: #{inspect(reason)}"
)
Log.error(fn ->
"AgentServer #{agent_id} failed to persist cron cancellation for #{Log.safe_inspect(logical_id)}: " <>
Log.safe_inspect(reason)
end)

emit_telemetry(state, :persist_failure, %{
job_id: logical_id,
Expand All @@ -66,9 +69,10 @@ defimpl Jido.AgentServer.DirectiveExec, for: Jido.Agent.Directive.CronCancel do
{:ok, new_state}

{:error, reason} ->
Logger.error(
"AgentServer #{agent_id} failed to persist cron cancellation for #{inspect(logical_id)}: #{inspect(reason)}"
)
Log.error(fn ->
"AgentServer #{agent_id} failed to persist cron cancellation for #{Log.safe_inspect(logical_id)}: " <>
Log.safe_inspect(reason)
end)

emit_telemetry(state, :persist_failure, %{
job_id: logical_id,
Expand Down
12 changes: 6 additions & 6 deletions lib/jido/agent/instance_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ defmodule Jido.Agent.InstanceManager do

use Supervisor

require Logger

alias Jido.Config.Defaults
alias Jido.Log
alias Jido.Persist
alias Jido.Storage

Expand Down Expand Up @@ -380,16 +379,17 @@ defmodule Jido.Agent.InstanceManager do

case Persist.thaw(storage, agent_module, persistence_key) do
{:ok, agent} ->
Logger.debug("InstanceManager thawed agent for key #{inspect(key)}")
Log.debug(fn -> "InstanceManager thawed agent for key #{Log.safe_inspect(key)}" end)
agent

{:error, :not_found} ->
nil

{:error, reason} ->
Logger.warning(
"InstanceManager failed to thaw agent for key #{inspect(key)}: #{inspect(reason)}"
)
Log.warning(fn ->
"InstanceManager failed to thaw agent for key #{Log.safe_inspect(key)}: " <>
Log.safe_inspect(reason)
end)

nil
end
Expand Down
Loading
Loading