Skip to content

Instantly share code, notes, and snippets.

@valinurovam
Created August 15, 2012 10:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save valinurovam/3358483 to your computer and use it in GitHub Desktop.
Save valinurovam/3358483 to your computer and use it in GitHub Desktop.
process_file(StatusFileName, Table) ->
FileName = ?STATUS_FILES_DIR ++ StatusFileName,
case file:open(FileName, read) of
{ok, IoD} ->
HttpURL = io:get_line(IoD, ''),
case httpc:request(HttpURL) of
{ok, {{_Version, HttpStatus, ReasonPhrase}, _Headers, _Body}} ->
case HttpStatus of
200 ->
file:delete(FileName),
ets:insert(Table, {StatusFileName, -1});
_OtherStatus ->
ets:insert(Table, {StatusFileName, 0})
end,
LogString = io_lib:format("~p ~p ~p ~p~n", [get_date_time(), HttpURL, HttpStatus, ReasonPhrase]);
OtherError ->
ets:insert(Table, {StatusFileName, 0}),
LogString = io_lib:format("~p ~p ~p~n", [get_date_time(), HttpURL, OtherError])
end,
log(LogString),
file:close(IoD);
{error, Reason} ->
ets:insert(Table, {StatusFileName, 0}),
LogString = io_lib:format("~p Error of open file ~p. Reason: ~p~n", [get_date_time(), FileName, Reason]),
log(LogString)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment