Hello everyone,
I am trying to create a function to schedule automatic functions with jam.py V7.
The idea is to implement apscheduler to schedule the automatic sending of emails.
For example:
a function that automatically generates customer statements every night and sends payment reminders by email.
I installed apscheduler and tried to modify the local “server.py” file to launch a function contained in the local “wsgi.py” file, but I can't seem to “hook up” to the items.
This is the modified server.py file
#!/usr/bin/env python
print(f"User Guide:
https://jampy-docs-v7.readthedocs.io/")
if __name__ == '__main__':
from jam.wsgi import create_application
from jam.wsgi_server import run
application = create_application(__file__)
# start sched
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
import atexit
# Importa la tua funzione
from wsgi import start_batch
# from jam.wsgi import App
# esegui_task = App.esegui_task
# Setup APScheduler
scheduler = BackgroundScheduler()
scheduler.add_job(
func = start_batch,
trigger = IntervalTrigger(seconds = 60),
id = 'stark_task_job',
name ='Execute esegui_task() every 60 seconds',
replace_existing = True
)
scheduler.start()
atexit.register(lambda: scheduler.shutdown())
# end sched
run(application)
and this is wsgi.py
from jam.wsgi import create_application
application = create_application(__file__)
# start sched
def start_batch():
print("wsgi.start_batch")
task_id = 12
item = application. ?????? .items(['batch_job']) # Sostituisci con il nome corretto
item.open() # Apre il dataset (eventualmente con filtro vuoto)
for r in item:
print(r['nome_campo']) # Sostituisci con un campo esistente
# if 'batch_job' in app.items:
# batch_job = app.items['batch_job']
def new_func():
return create_application(__file__)
# puoi aggiornare lo stato del task ad "eseguito", ecc.
I'm not an expert in Python... in fact, I know very little about it.
Can anyone give me an idea?
What should I put where there are ????
If I succeed, I'll post everything.
Thanks
Translated with DeepL.com (free version)