Skip to content

Commit

Permalink
feat(script): implement script to sequentially hit by thread route an…
Browse files Browse the repository at this point in the history
…d log when there is an error
  • Loading branch information
akinsey committed Dec 13, 2024
1 parent e73fffc commit 288e215
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions parse_by_thread.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Mix.install([{:httpoison, "~> 2.0"}, {:logger_file_backend, "~> 0.0.10"},])

defmodule ParseByThread do
require Logger

Logger.add_backend {LoggerFileBackend, :error}
Logger.configure_backend {LoggerFileBackend, :error},
path: "./parse_by_thread_error.log",
level: :error

@start_id 5_485_059
@end_id 1

def run do
for id <- @start_id..@end_id//-1 do
case HTTPoison.get("http://localhost:4000/api/posts?thread_id=#{id}") do
{:ok, %HTTPoison.Response{status_code: 200, body: _body}} ->
Logger.info("Successfully parsed thread with id (#{id})")
{:ok, %HTTPoison.Response{status_code: status_code}} ->
Logger.error("Thread with id (#{id}) received response with status code #{status_code}")
{:error, %HTTPoison.Error{reason: reason}} ->
Logger.error("Thread with id (#{id}) HTTP request failed: #{reason}")
end
end
end
end

ParseByThread.run()

0 comments on commit 288e215

Please sign in to comment.