New option args_type useful when the function expects arguments as strings
This commit is contained in:
parent
03cd4de6b0
commit
3d523cec45
|
@ -27,11 +27,12 @@ modules:
|
|||
TASK SYNTAX
|
||||
===========
|
||||
|
||||
Each task is described with five elements:
|
||||
Tasks are described with those 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 array. Strings will be converted to binaries.
|
||||
* Arguments is an array. By default strings will be converted to binaries.
|
||||
* args_type can be set to string, if the function expects strings instead of binaries
|
||||
* timer_type is one of 'fixed' or 'interval'. Fixed timers occur at a fixed time
|
||||
after the [minute|hour|day] e.g. every hour on the 5th minute (1:05PM, 2:05PM etc)
|
||||
interval timers occur every interval (starting on an even unit) e.g. every 10 minutes
|
||||
|
@ -64,6 +65,14 @@ modules:
|
|||
- "localhost"
|
||||
- "somepass"
|
||||
timer_type: interval
|
||||
- time: 24
|
||||
units: hours
|
||||
module: mnesia
|
||||
function: backup
|
||||
timer_type: interval
|
||||
args_type: string
|
||||
arguments:
|
||||
- "/var/log/ejabberd/mnesia.backup"
|
||||
|
||||
|
||||
EJABBERD COMMANDS
|
||||
|
|
|
@ -139,8 +139,9 @@ update_timer_ref(TaskId, NewTimerRef) ->
|
|||
|
||||
%% Method to add new task
|
||||
add_task(Host, Task) ->
|
||||
[TimeNum, TimeUnit, Mod, Fun, Args, InTimerType] =
|
||||
[proplists:get_value(Key, Task) || Key <- [time, units, module, function, arguments, timer_type]],
|
||||
[TimeNum, TimeUnit, Mod, Fun, ArgsType, Args1, InTimerType] =
|
||||
[proplists:get_value(Key, Task) || Key <- [time, units, module, function,
|
||||
args_type, arguments, timer_type]],
|
||||
TimerType = case InTimerType of
|
||||
<<"fixed">> ->
|
||||
fixed;
|
||||
|
@ -153,6 +154,11 @@ add_task(Host, Task) ->
|
|||
%% Get new task identifier
|
||||
TaskId = get_new_taskid(),
|
||||
|
||||
Args = case ArgsType of
|
||||
string -> [binary_to_list(Arg) || Arg <- Args1];
|
||||
_ -> Args1
|
||||
end,
|
||||
|
||||
TimerRef = case TimerType of
|
||||
interval ->
|
||||
begin_interval_timer(TaskId, TimeUnit, TimeNum, [Mod, Fun, Args]);
|
||||
|
|
Loading…
Reference in New Issue