X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=modules%2Ferl%2Feuphorik_daemon.erl;h=190458e203d977bbb4d7d92a3164b2e657616671;hp=051e26d869253510f4fd559440c6bb061ac04006;hb=5d9992368bb386d2e606ae037c5478fe10ac70e8;hpb=221a44d7aeaf467ef9854fe21af93bc964e92ef1 diff --git a/modules/erl/euphorik_daemon.erl b/modules/erl/euphorik_daemon.erl index 051e26d..190458e 100755 --- a/modules/erl/euphorik_daemon.erl +++ b/modules/erl/euphorik_daemon.erl @@ -1,30 +1,61 @@ -% Module tournant en background s'occupant periodiquement de certaines tâches : -% - Élection du prochain troll chaque semaine -% Date : 05.11.2007 -% @author G.Burri +% coding: utf-8 +% Copyright 2008 Grégory Burri +% +% This file is part of Euphorik. +% +% Euphorik is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Euphorik is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Euphorik. If not, see . +% +% Module tournant en background s'occupant periodiquement de certaines tâches : +% - rechargement des modules lors d'une mise en production --module(euphorik_daemon). --export([start/1]). --include("../include/euphorik_defines.hrl"). - - -% Démarre le démon + +-module(euphorik_daemon). +-author("Greg Burri "). +-export([start/1, reload_euphorik/0, loop/0]). +-include("../include/euphorik_defines.hrl"). + + +% Démarre le démon start(_A) -> - loop(). - -loop() -> - % on attend une minute de plus pour prevenir une dérive négative - timer:sleep(1000 * trunc(temps_prochaine_election() + 60)), - euphorik_bd:elire_troll(), - loop(). - - -% Renvoie le nombre de seconde qu'il reste jusque au prochain lundi à l'heure donnée (l'heure est sur 24heures) -% 86400 est le nombre de seconde dans un jour -temps_prochaine_election() -> - {Date, {H,M,S}} = calendar:local_time(), - Delta = (?JOUR_ELECTION_TROLL - 1) * 86400 + ?HEURE_ELECTION_TROLL * 60 * 60 - -((calendar:day_of_the_week(Date) - 1) * 86400 + H * 60 * 60 + M * 60 + S), - % attention au cas où les deux dates (maintenant et la date d'élection) ne se trouvent pas dans la même semaine. - if Delta =< 0 -> Delta + 7 * 86400; true -> Delta end. - + register(euphorik_daemon, self()), + loop(). + + +loop() -> + receive + switch -> % To reload a new code, see 'reload_euphorik/0'. + euphorik_daemon:loop() + end. + +% Recharge tous les modules euphorik. +% Appelé lors d'une mise en prod. +% TODO : récupérer les noms à partir des .beam dans /modules/ebin +reload_euphorik() -> + lists:foreach( + fun(M) -> + c:l(M) % (purge & load) + end, + [ + euphorik_common, + euphorik_minichat_conversation, + euphorik_protocole, + euphorik_requests, + euphorik_bd, + euphorik_bd_admin, + euphorik_daemon + ] + ), + % changement du code du daemon + euphorik_daemon ! switch, + ok.