mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 23:50:59 +00:00
Guard against valid units
This commit is contained in:
parent
e4dd585e39
commit
545594f1e5
3 changed files with 4 additions and 4 deletions
|
@ -26,7 +26,7 @@ defmodule LiveBeats.Application do
|
|||
name: PresenceClient},
|
||||
# Start the Endpoint (http/https)
|
||||
LiveBeatsWeb.Endpoint,
|
||||
{LiveBeats.SongsCleaner, count: 1, interval: "month"}
|
||||
{LiveBeats.SongsCleaner, count: 1, interval: :month}
|
||||
|
||||
# Start a worker by calling: LiveBeats.Worker.start_link(arg)
|
||||
# {LiveBeats.Worker, arg}
|
||||
|
|
|
@ -366,12 +366,12 @@ defmodule LiveBeats.MediaLibrary do
|
|||
end
|
||||
end
|
||||
|
||||
def expire_songs_older_than(count, interval) do
|
||||
def expire_songs_older_than(count, interval) when interval in [:month, :day, :second] do
|
||||
Ecto.Multi.new()
|
||||
|> Ecto.Multi.delete_all(
|
||||
:delete_expired_songs,
|
||||
from(s in Song,
|
||||
where: s.inserted_at < from_now(^(-count), ^interval),
|
||||
where: s.inserted_at < from_now(^(-count), ^to_string(interval)),
|
||||
select: %{user_id: s.user_id, mp3_filepath: s.mp3_filepath}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -86,7 +86,7 @@ defmodule LiveBeats.MediaLibraryTest do
|
|||
|
||||
active_song = song_fixture(user_id: user.id, title: "song3", inserted_at: one_month_ago)
|
||||
|
||||
MediaLibrary.expire_songs_older_than(2, "month")
|
||||
MediaLibrary.expire_songs_older_than(2, :month)
|
||||
|
||||
assert_raise Ecto.NoResultsError, fn -> MediaLibrary.get_song!(expired_song_1.id) end
|
||||
assert_raise Ecto.NoResultsError, fn -> MediaLibrary.get_song!(expired_song_2.id) end
|
||||
|
|
Loading…
Reference in a new issue