Hello as general discussion, I just wanted to know that if anybody see any thing wrong in this code
try do
task = Task.async(fn() ->
datetime =
timestamp
|> Calendar.DateTime.Parse.unix!
|> Calendar.DateTime.to_erl
|> Ecto.DateTime.cast!
params = construct_camera(datetime, status, camera.is_online == status)
changeset = Camera.changeset(camera, params)
camera = Repo.update!(changeset)
log_camera_status(camera, status, datetime, error_code)
broadcast_change_to_users(camera)
Camera.invalidate_camera(camera)
end)
Task.await(task, :timer.seconds(3))
catch _type, error ->
Util.error_handler(error)
end
where as the the logging status code is
def log_camera_status(camera, true, datetime, nil), do: do_log_camera_status(camera, "online", datetime)
def log_camera_status(camera, false, datetime, error_code), do: do_log_camera_status(camera, "offline", datetime, %{reason: error_code})
defp do_log_camera_status(camera, status, datetime, extra \\ nil) do
spawn fn ->
case check_last_camera_status(camera.id, status) do
true ->
parameters = %{camera_id: camera.id, camera_exid: camera.exid, action: status, done_at: datetime, extra: extra}
changeset = CameraActivity.changeset(%CameraActivity{}, parameters)
SnapshotRepo.insert(changeset)
send_notification(status, camera, camera.alert_emails)
false -> :noop
end
end
end
I dont know the reasons but sometime may be most of the time… this whole process get crashed at Task.await(task, :timer.seconds(3))
this… Anybody can point me if they see something wrong?