I have written a small daemon script which will check status of model(Foo) field and if it is 0 then update another model(Bar) and if it is 1 then don't do anything.
The daemon is running fine, And it is updating as we expected if the models status is 0.
Please find the link to the script from here: click
But once we start the daemon script, it is unable to read the database changes after that. Means, after the daemon has started running even if an object is created in model Foo with status 0, daemon is not able to read it, consequently the model Bar is not getting updated as expected.
How could I resolve this issue?
The fundamental problem was, on subsequent daemon process checks, the database state was same as when daemon started.
I got hint for the solution from this link.
Before each orm query, I reset the connection and now the orm is reading the updated database.
def reset_database_connection():
from django import db
db.close_connection()