Kapacitor task on demand aka launched only manually


I need a batch task to be executed only on demand during 2 dates.
This task should never be runned automatically.
So I cannot put a .every() on it, neither a .cron(). The language force me to give one of the two.

To get around of this, I did put the cron “.cron(‘0 0 0 30 2 0 *’)”. I hope it will be enough to not be executed, if you think the contrary please tell me. The sad part of this dirty approach is that I cannot use the replay between two date feature, it does not play well with .cron() task. So I need to make a record and replay the record then delete the record. Also part of the business part of the code, the query itself, is extracted out of the task.

Do you have another idea about a better way of implementing this batch task on demand ?
I was thinking that maybe removing the mandatory .every or .cron could made it.

Thanks for your advises.

1 Like

If you don’t need a Kapacitor-specific alert, you could always use a regular InfluxQL.

But there is a way to do this, simply define the batch task but do not enable it.

Then make an API call to Kapacitor using the replay features to run the task on what ever time range you need. Check out this doc to see if it fits your needs. You can still replay a task that’s disabled.


Here is an example. I hope that helps!