-1

I want to do some task 10 times every hour. Or 10 times every day, or 3 times every day etc etc. I want this to be dynamic so I can just give 2 parameters, like:

generate_random_task(times, frequency)
generate_random_task(10, daily):
    randomly do the task be 10 times during a day.

I must keep track of how many times the task has been done, so its stops to do it after it reached "times"

Just to make it clear, the 10 times the task must be done, must be at 10 random times

What would be a nice way to do this?

EDIT: I will hit some function every now and then (completely random), then instantly i must know if the task will run or not. So I cant used celery that will so something 10 times in the day. I need to instantly know if its YES or NO.

Harry
  • 13,091
  • 29
  • 107
  • 167

1 Answers1

1

Isn't it sufficient to run a cron job once a minute which will make a decision whether to perform your task or not and if so, do it? You could keep a file which contains the number of times it's done it and use that to stop if don't need it anymore.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169