These two work fine when tested for few minutes. But I am not sure if this is a proper way of doing this and if these gears wont conflict with internal logic like timeouts. Also I donât know what will happen on crashes and restarts. Or if they will slowly run out of memory.
The reason of not wanting external scripts to periodically run batch commands - I donât want to introduce another point of failure.
We actually have this future planed to be supported build-in inside RedisGears in future versions, so stay tuned. Until then I have a few comments and a suggestion for another approach.
The issue I see with what you did is that you basically have a forever running execution (the first execution that writes to the key never finished). This implies that you consume a thread from the thread pool forever and you are limited by the number of threads in the thread pool (https://oss.redislabs.com/redisgears/configuration.html#executionthreads). In addition, your approach will not survive restart because the execution will not restart after the server restart.
Here is my suggestion, You create a registration that registers on key expiration. Inside the OnRegister callback, you set the key with whatever expiration you want, when calculation finished you re-add the key with whatever expiration you want (to basically reschedule the job):
You will consume a thread from the thread pool only when the job is running and not forever
You will survive restarts, the OnRegister callback will be called on each shard on the RDB/AOF load phase so this will basically reschedule your job.
Please notice that there is one disadvantage here, Redis has 2 types of mechanisms for keys expiration, active expire, and passive expire (to read more about it look here https://redis.io/commands/expire). Basically what it means is that you might get the expire event in some delay and this delay is affected by the total number of expired keys and the amount of effort Redis is configured to do active expire. I do believe though that for cron jobs this solution is good enough.
Hope everything is clear, let me know what you think.