mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
delete files as task
This commit is contained in:
@@ -59,7 +59,19 @@ defmodule PlantIdDiscordBot.FileServer.File do
|
|||||||
# TODO make into a task for async deletion and deal with errors
|
# TODO make into a task for async deletion and deal with errors
|
||||||
@spec delete_files!([String.t()]) :: :ok
|
@spec delete_files!([String.t()]) :: :ok
|
||||||
def delete_files!(filenames) do
|
def delete_files!(filenames) do
|
||||||
Enum.each(filenames, &File.rm!(Path.join(@image_path, &1)))
|
tasks =
|
||||||
|
Enum.map(filenames, fn filename ->
|
||||||
|
Task.async(fn ->
|
||||||
|
try do
|
||||||
|
File.rm!(Path.join(@image_path, filename))
|
||||||
|
rescue
|
||||||
|
# TODO Logger
|
||||||
|
e -> IO.inspect(e)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
Enum.map(tasks, &Task.await/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec download_file!(String.t()) :: binary
|
@spec download_file!(String.t()) :: binary
|
||||||
|
|||||||
Reference in New Issue
Block a user