Update mod_cron for better YAML config support

This commit is contained in:
Badlop 2015-01-28 17:12:59 +01:00
parent 44f709ba38
commit edb67df064
2 changed files with 28 additions and 36 deletions

View File

@ -19,55 +19,46 @@ ejabberd log file.
BASIC CONFIGURATION BASIC CONFIGURATION
=================== ===================
Add the module to the modules configuration. Add the module to your ejabberd.yml, on the modules section:
As it requires complex configuration, add this to the ejabberd.yml file: modules:
include_config_file: "/etc/ejabberd/additional.cfg" mod_cron: {}
And this to additional.cfg:
{modules, [
{mod_cron, []},
]}.
TASK SYNTAX TASK SYNTAX
=========== ===========
Each task is described using a tuple with this syntax: Each task is described with five elements:
{Time, Time_units, Module, Function, Arguments} * Time is an integer.
Where: * Units indicates the time unit you use. It can be: seconds, minutes, hours, days.
Time is an integer. * Module and * Function are the exact call you want to schedule.
Time_units indicates the time unit you use. It can be: seconds, minutes, hours, days. * Arguments is an erlang list of arguments inside the characters "> ."
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"]}
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 Example configuration with some tasks:
For example: modules:
{modules, [ mod_cron:
... tasks:
{mod_cron, [{tasks, [ - time: 3
{3, hours, mnesia, info, []}, units: hours
{1, days, ejabberd_auth, try_register, ["aaa", "atenea", "aaaaaa"]} module: mnesia
]}]}, function: info
... arguments: "> []."
]}. - time: 10
units: seconds
module: ejabberd_auth
function: try_register
arguments: "> [\"user1\", \"localhost\", \"somepass\"]."
EJABBERD COMMANDS EJABBERD COMMANDS
================= =================
This module provides two new commands that can be executed using ejabberdctl: This module provides two new commands that can be executed using ejabberdctl:
* cron-list: list scheduled tasks * cron_list: list scheduled tasks
* cron-del taskid: delete this task from the schedule * cron_del taskid: delete this task from the schedule
WEB ADMIN WEB ADMIN

View File

@ -54,7 +54,8 @@ stop(Host) ->
%% Method to add new task %% Method to add new task
add_task(Host, 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 %% Convert to miliseconds
Time = case Time_unit of Time = case Time_unit of