当前位置: 动力学知识库 > 问答 > 编程问答 >

Python / Django - Do something X times every X hour

问题描述:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: