Skip to content

Commit

Permalink
Run jobs as tasks and remove unneeded log (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim authored Oct 5, 2023
1 parent 78c953d commit c9f365f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
5 changes: 0 additions & 5 deletions lib/jobs/message_latency_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ defmodule Jobs.MessageLatencyReport do
|> Stream.filter(&filter_by_date(&1, date))
|> Stream.map(fn row -> row[:seconds] end)
|> Enum.sort()
|> tap(fn _ ->
Logger.info(
with_message_latency_report_tag("Memory in use after sort: #{:erlang.memory(:total)}")
)
end)
|> Stream.with_index()
|> get_percentiles()

Expand Down
25 changes: 15 additions & 10 deletions lib/realtime_signs_web/controllers/monitoring_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ defmodule RealtimeSignsWeb.MonitoringController do
Param "date" can be in either YYYY-MM-DD or YYYYMMDD formats
"""
def run_message_log_job(conn, %{"date" => date} = _params) do
Logger.info("Starting job to request and store message logs...")
RealtimeSigns.MessageLogJob.get_and_store_logs(date)
Task.start(fn ->
Logger.info("Starting job to request and store message logs...")
RealtimeSigns.MessageLogJob.get_and_store_logs(date)
end)

send_resp(conn, 200, "")
end

Expand All @@ -29,14 +32,16 @@ defmodule RealtimeSignsWeb.MonitoringController do
Param "days" is an integer used to tell the job how many days back it should analyze
"""
def run_message_latency_report(conn, %{"start_date" => start_date, "days" => days} = _params) do
Logger.info(
"Beginning manual run of message latency report starting from #{start_date} going back #{days} days"
)

Jobs.MessageLatencyReport.generate_message_latency_reports(
Date.from_iso8601!(start_date),
String.to_integer(days)
)
Task.start(fn ->
Logger.info(
"Beginning manual run of message latency report starting from #{start_date} going back #{days} days"
)

Jobs.MessageLatencyReport.generate_message_latency_reports(
Date.from_iso8601!(start_date),
String.to_integer(days)
)
end)

send_resp(conn, 200, "")
end
Expand Down

0 comments on commit c9f365f

Please sign in to comment.