X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=modules%2Ferl%2Feuphorik_daemon.erl;h=00825a03079f47b8b4b15778e24d33517ed343df;hp=5760332bacc78005764a58e41e907da5b4b0816b;hb=6d1aeefe7c166ab9033d69347d85bb7eb20d0fa8;hpb=31bccc69493f5faf2408a4fb923ad7e88df18b8b diff --git a/modules/erl/euphorik_daemon.erl b/modules/erl/euphorik_daemon.erl index 5760332..00825a0 100755 --- a/modules/erl/euphorik_daemon.erl +++ b/modules/erl/euphorik_daemon.erl @@ -1,22 +1,63 @@ -% Module tournant en background s'occupant periodiquement de certaines tâches. -% Auteur : G.Burri -% Date : 05.11.2007 +% 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 : +% - sélection du prochain troll chaque semaine +% - rechargement des modules lors d'une mise en production +% Date : 05.11.2007 +% @author G.Burri + -module(euphorik_daemon). --export([start/1]). - --include("../include/euphorik_defines.hrl"). - - -% Démarre le démon -start(A) -> - loop(A). +-export([start/1, reload_euphorik/0]). +-include("../include/euphorik_defines.hrl"). - -loop(A) -> +% 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(), - timer:sleep(1000), - loop(A). - + euphorik_daemon: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ù 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. +% 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) -> + code:purge(M), + code:load_file(M) + end, + [euphorik_common, euphorik_minichat_conversation, euphorik_protocole, euphorik_requests, euphorik_bd, euphorik_daemon] + ). + \ No newline at end of file