From edb67df06464cc3656b926f964043ee95dae0df5 Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 28 Jan 2015 17:12:59 +0100 Subject: [PATCH] Update mod_cron for better YAML config support --- mod_cron/README.txt | 61 +++++++++++++++++---------------------- mod_cron/src/mod_cron.erl | 3 +- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/mod_cron/README.txt b/mod_cron/README.txt index 45bd653..a7d6ffa 100644 --- a/mod_cron/README.txt +++ b/mod_cron/README.txt @@ -19,55 +19,46 @@ ejabberd log file. BASIC CONFIGURATION =================== -Add the module to the modules configuration. -As it requires complex configuration, add this to the ejabberd.yml file: - include_config_file: "/etc/ejabberd/additional.cfg" -And this to additional.cfg: -{modules, [ - {mod_cron, []}, -]}. +Add the module to your ejabberd.yml, on the modules section: +modules: + mod_cron: {} TASK SYNTAX =========== -Each task is described using a tuple with this syntax: - {Time, Time_units, Module, Function, Arguments} -Where: - Time is an integer. - Time_units indicates the time unit you use. It can be: seconds, minutes, hours, days. - Module and Function are the exact call you want to schedule. - Arguments is a list of arguments. It can be emtpy. - -For example, let's define some dummy tasks: - * Every 3 hours, print on the log file some info about mnesia: - {3, hours, mnesia, info, []} - - * Every day, try to register certain account: - {1, days, ejabberd_auth, try_register, ["tommy", "jabber.example.org", "MyP455WorD"]} +Each task is described with five elements: +* Time is an integer. +* Units indicates the time unit you use. It can be: seconds, minutes, hours, days. +* Module and * Function are the exact call you want to schedule. +* Arguments is an erlang list of arguments inside the characters "> ." - TASKS ON EJABBERD.CFG - ===================== + EXAMPLE TASKS + ============= -Now that you know how to define new tasks, you can add the ones you want on ejabberd.cfg -For example: -{modules, [ - ... - {mod_cron, [{tasks, [ - {3, hours, mnesia, info, []}, - {1, days, ejabberd_auth, try_register, ["aaa", "atenea", "aaaaaa"]} - ]}]}, - ... -]}. +Example configuration with some tasks: +modules: + mod_cron: + tasks: + - time: 3 + units: hours + module: mnesia + function: info + arguments: "> []." + - time: 10 + units: seconds + module: ejabberd_auth + function: try_register + arguments: "> [\"user1\", \"localhost\", \"somepass\"]." EJABBERD COMMANDS ================= This module provides two new commands that can be executed using ejabberdctl: - * cron-list: list scheduled tasks - * cron-del taskid: delete this task from the schedule +* cron_list: list scheduled tasks +* cron_del taskid: delete this task from the schedule WEB ADMIN diff --git a/mod_cron/src/mod_cron.erl b/mod_cron/src/mod_cron.erl index 2c97980..76a6087 100644 --- a/mod_cron/src/mod_cron.erl +++ b/mod_cron/src/mod_cron.erl @@ -54,7 +54,8 @@ stop(Host) -> %% Method to add new task add_task(Host, Task) -> - {Time_num, Time_unit, Mod, Fun, Args} = Task, + [Time_num, Time_unit, Mod, Fun, Args] = + [proplists:get_value(Key, Task) || Key <- [time, units, module, function, arguments]], %% Convert to miliseconds Time = case Time_unit of