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
===================
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

View File

@ -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