I want to implement something similar to this, where the custom function classify_process() continuously asks a Redis db for new entries.
Can this be done a regular SQL table? The db.pipeline() seems to be Redis-specific, so I'm not sure how to imitate this functionality on a SQL db.
My goal is to check one table for new rows, and if there's a new row, run a prediction using a ML model.
QUESTION: How can I continously check if there are any new records in a MS SQL table (which has an interger ID column that automatically increments) and then trigger a function?
My idea of what has to happen using sqlalchemy:
import time
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
DRIVER = 'driver'
SERVER = 'server'
DATABASE = 'database'
engine = create_engine(f'mssql+pyodbc://{SERVER}/{DATABASE}?{DRIVER}')
SessionLocal = sessionmaker(bind=engine)
def some_process():
while True:
# look for new rows in table, then execute prediction on newest rows
...some code...?
# Sleep for x seconds
time.sleep(5)
if __name__ == "__main__":
some_process()