I am making a django application. To calculate the rank of the feeds based on lines and comment, I am trying to use django-background-tasks. the function I am using in nodes models is:
@background(schedule=60)
def get_score(self):
p = self.likes+self.comments # popularity
t = (now()-self.date).total_seconds()/3600 # age_in_hrs
# last_activity =
n = self.admin_score
score = (p/pow((t+1), 1.2))*n
self.score = score
return score
But I am not seeing any change in score. That means that I am doing it in a right way and i am missing the basic concept. Can somebody tell me how to use django-background-tasks to schedule task or refer me to some existing documents.
You seem to be using it the wrong way.
Let's say you have to execute some particular task say, send a mail 5 minutes after a user signs up. So what do you do is:
Create a task using django-background-task.
The decorator at the top defines after how much time of the function getting called upon is the actual event gonna happen.
Call it when you need it.
This creates the task and saves it in database and also storing in db the time when it will be executed.
The kind of thing you want to do, doing something at regular intervals, that can more easily be done by creating cron job.
What you do is, you create a function as you have shown in the question. And then define a cron job to call it every 5 minutes or whatever interval you want.