Here is what I did:
from flask import Flask
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
dbhost = 'localhost'
dbuser = 'user'
dbpass = 'password'
dbname = 'db'
DBUri = 'mysql://%s:%s@%s/%s?charset=utf8'%(dbuser,dbpass,dbhost,dbname)
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = (DBUri)
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
# an Engine, which the Session will use for connection
# resources
engine = create_engine(DBUri)
# create a configured "Session" class
Session = sessionmaker(bind=engine)
# create a Session
DBsession = Session()
and
@sched.cron_schedule(second='*/5')
def some_decorated_task():
date_now = datetime.datetime.now().date()
for item in DBsession.query(user_groups_n_hosts).filter(user_groups_n_hosts.end_time < str(date_now)):
print item.id, item.server_users.native_linux_user
there is a table user_groups_n_hosts The above code is a function that runs every 30 seconds.
My problem is that Once I start my Flask application at that time if the user_groups_n_hosts has 10 records then the above code will keep printing 10 records no matter whatever number of records get inserted in the table user_groups_n_hosts from outside. In other words what I think is that My function has some instance of the table which is only initialized in the beginning of the initialization of the app. I know I am doing something stupid. please someone point it out.
in place of DBsession.query(user_groups_n_hosts).filter(user_groups_n_hosts.end_time < str(date_now)):
I tried user_groups_n_hosts.query.filter(user_groups_n_hosts.end_time < str(date_now)):
But the result is same.