-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Delete realtime.messages entries older than 72h on connect (#1164)
Starts a clean up task on each node to delete the messages in `realtime.message`. It checks: * Which tenants need cleanup on a given region * If the tenant should be cleaned by a given node * Chunks the groups of tenants to avoid overloading Realtime.Repo and number of connections from a given node * Starts connections for each tenant * Runs query to delete messages older than 72h We need two setups needed for tests: * Self hosted isn't connected as a cluster nor has a region so we need a default behaviour for "regionless" setups * For Node mode, we need to emulate the region and emulate the node connected This impacts Cachex tests which is why we had to change to have max_cases set to 1 to avoid parallel tests from other modules to interfere Finally, we also need to define if the application starts or not the scheduled tasks. This helps with tests but also helps if we need to stop this processes in production.
- Loading branch information
1 parent
ac23ca5
commit 6a1ae6b
Showing
15 changed files
with
496 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Realtime.Messages do | ||
@moduledoc """ | ||
Handles `realtime.messages` table operations | ||
""" | ||
import Ecto.Query | ||
alias Realtime.Repo | ||
alias Realtime.Api.Message | ||
|
||
@doc """ | ||
Deletes messages older than 72 hours for a given tenant connection | ||
""" | ||
@spec delete_old_messages(pid()) :: {:ok, any()} | {:error, any()} | ||
def delete_old_messages(conn) do | ||
limit = NaiveDateTime.utc_now() |> NaiveDateTime.add(-72, :hour) | ||
query = from m in Message, where: m.inserted_at <= ^limit | ||
Repo.del(conn, query) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.