| 1 |
|
-module(shurbej_session_cleaner). |
| 2 |
|
-behaviour(gen_server). |
| 3 |
|
|
| 4 |
|
%% Periodically cleans up expired login sessions and orphaned uploads. |
| 5 |
|
|
| 6 |
|
-export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2]). |
| 7 |
|
|
| 8 |
|
-define(CLEANUP_INTERVAL, 60000). %% 1 minute |
| 9 |
|
-define(SESSION_TTL_MS, 600000). %% 10 minutes (must match shurbej_session) |
| 10 |
|
-define(UPLOAD_TTL_MS, 3600000). %% 1 hour for pending uploads |
| 11 |
|
|
| 12 |
|
start_link() -> |
| 13 |
1 |
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). |
| 14 |
|
|
| 15 |
|
init([]) -> |
| 16 |
1 |
erlang:send_after(?CLEANUP_INTERVAL, self(), cleanup), |
| 17 |
1 |
{ok, #{}}. |
| 18 |
|
|
| 19 |
|
handle_call(_Msg, _From, State) -> |
| 20 |
:-( |
{reply, ok, State}. |
| 21 |
|
|
| 22 |
|
handle_cast(_Msg, State) -> |
| 23 |
:-( |
{noreply, State}. |
| 24 |
|
|
| 25 |
|
handle_info(cleanup, State) -> |
| 26 |
1 |
cleanup_sessions(), |
| 27 |
1 |
cleanup_uploads(), |
| 28 |
1 |
erlang:send_after(?CLEANUP_INTERVAL, self(), cleanup), |
| 29 |
1 |
{noreply, State}; |
| 30 |
|
handle_info(_Msg, State) -> |
| 31 |
:-( |
{noreply, State}. |
| 32 |
|
|
| 33 |
|
cleanup_sessions() -> |
| 34 |
1 |
shurbej_session:cleanup_expired(). |
| 35 |
|
|
| 36 |
|
cleanup_uploads() -> |
| 37 |
1 |
shurbej_files:cleanup_expired_uploads(). |