Skip to content

Commit

Permalink
Remove Credo.Execution.Monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Oct 26, 2018
1 parent a6ae0a9 commit d7525cd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.
55 changes: 0 additions & 55 deletions lib/credo/execution/monitor.ex

This file was deleted.

58 changes: 56 additions & 2 deletions lib/credo/execution/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ defmodule Credo.Execution.Task do

@callback call(exec :: Credo.Execution.t(), opts :: Keyword.t()) :: Credo.Execution.t()

require Logger

alias Credo.Execution
alias Credo.Execution.Monitor
alias Credo.Execution.ExecutionTiming

defmacro __using__(_opts \\ []) do
quote do
Expand Down Expand Up @@ -36,7 +38,7 @@ defmodule Credo.Execution.Task do
def run(task, exec, opts \\ [])

def run(task, %Credo.Execution{debug: true} = exec, opts) do
Monitor.task(exec, task, opts, &do_run/3, [task, exec, opts])
run_with_timing(task, exec, opts)
end

def run(task, exec, opts) do
Expand Down Expand Up @@ -79,4 +81,56 @@ defmodule Credo.Execution.Task do

exec
end

#

defp run_with_timing(task, exec, opts) do
context_tuple = {:task, exec, task, opts}
log(:call_start, context_tuple)

{started_at, time, exec} = ExecutionTiming.run(&do_run/3, [task, exec, opts])

log(:call_end, context_tuple, time)

ExecutionTiming.append(exec, [task: task, parent_task: exec.parent_task], started_at, time)

exec
end

defp log(:call_start, {:task_group, _exec, task_group, _opts}) do
Logger.info("Calling #{task_group} ...")
end

defp log(:call_start, {:task, _exec, task, _opts}) do
Logger.info("Calling #{task} ...")
end

defp log(:call_start, context_tuple) do
Logger.info("Calling #{inspect(context_tuple)} ...")
end

defp log(:call_end, {:task_group, _exec, task_group, _opts}, time) do
Logger.info("Finished #{task_group} in #{format_time(time)} ...")
end

defp log(:call_end, {:task, _exec, task, _opts}, time) do
Logger.info("Finished #{task} in #{format_time(time)} ...")
end

defp log(:call_end, context_tuple, time) do
Logger.info("Finished #{inspect(context_tuple)} in #{format_time(time)} ...")
end

defp format_time(time) do
cond do
time > 1_000_000 ->
"#{div(time, 1_000_000)}s"

time > 1_000 ->
"#{div(time, 1_000)}ms"

true ->
"#{time}μs"
end
end
end

0 comments on commit d7525cd

Please sign in to comment.