Question: mod_cron - schedule mysql mam purge
sando38 opened this issue · comments
Hello ejabberd frieds,
just a quick question:
I am running ejabberd with a mariaDB instance and within kubernetes. Currently, I have a cron-job scheduled on the host-machine
deleting mam archive for messages older than 30 days with
bin/ejabberdctl delete-old-mam-messages all 30
I understand that mod_cron calls the different modules of ejabberd, can the module also call the API like this:
modules:
mod_cron:
tasks:
- time: 90
units: minutes
module: api
function: ejabberdctl
arguments:
- "delete-old-mam-messages"
- "all"
- "30"
timer_type: fixed
Thanks in advance and wish you a great weekend!
Now that you mention, it is not possible to use API commands, and it is not possible to call functions when have mixed argument types. So, right now I see no way to use mod_cron for that.
I'll take a look the next days and ping you with a solution.
By the way, a new set of commands have been added right now:
delete_old_mam_messages_batch, ...
See processone/ejabberd@b86fe14
Thanks for the quick feedback and for having a look into it! Looking forward to it.
I've improved mod_cron, now there are three ways to purge mam messages!
I have also improved the mod_cron documentation: https://github.com/processone/ejabberd-contrib/tree/master/mod_cron
Those two methods should work correctly with ejabberd 21.12 and some older versions:
modules:
mod_cron:
tasks:
- time: 15
units: seconds
ctl: delete_old_mam_messages
arguments:
- "all"
- "0"
- time: 20
units: seconds
module: mod_mam
function: delete_old_messages
arguments:
- "all"
- 0
This requires using ejabberd from git:
modules:
mod_cron:
tasks:
- time: 10
units: seconds
command: delete_old_mam_messages # requires a recent ejabberd git
arguments:
- "all"
- 0
Nice, it works as expected.
I tested the following config with ejabberd 21.12:
modules:
mod_cron:
tasks:
- time: 60
units: minutes
timer_type: interval
ctl: delete_old_mam_messages
arguments:
- "all"
- "30"
I did not test the current ejabberd git version, no time to rebuild the docker image in the moment.
Since this is a very smooth solution, easy to use for people and with expanded administrative operations with the "API" extension, you may consider to include mod_cron into the core modules shipped directly with ejabberd builts like with your new 22.xx ejabberd version?
Thanks again for your work and this quick and easy update!