run in background
This commit is contained in:
parent
6db69e0c70
commit
f6d73021d0
@ -20,7 +20,7 @@ class TodoDatabase:
|
|||||||
self.database["recurring"] = []
|
self.database["recurring"] = []
|
||||||
if date not in self.database:
|
if date not in self.database:
|
||||||
# if not len(self.database[date]) > 0:
|
# if not len(self.database[date]) > 0:
|
||||||
self.database[date] = copy.deepcopy(self.database["recurring"])
|
self.database[date] = [] #copy.deepcopy(self.database["recurring"])
|
||||||
if todo.recurring:
|
if todo.recurring:
|
||||||
self.database["recurring"].append(todo.model_dump())
|
self.database["recurring"].append(todo.model_dump())
|
||||||
self.database[date].append(todo.model_dump())
|
self.database[date].append(todo.model_dump())
|
||||||
@ -37,6 +37,11 @@ class TodoDatabase:
|
|||||||
if date in self.database:
|
if date in self.database:
|
||||||
del self.database[date]
|
del self.database[date]
|
||||||
|
|
||||||
|
def remove_recurring(self, todo):
|
||||||
|
if 'recurring' in self.database:
|
||||||
|
self.database['recurring'] = [i for i in self.database['recurring'] if (i["time"] == todo.time and i['task'] == todo.task)]
|
||||||
|
# t = [i for i in t if i.name!="Remove me"]
|
||||||
|
|
||||||
def read_todos(self, date):
|
def read_todos(self, date):
|
||||||
# if self.datebase[date] is None:
|
# if self.datebase[date] is None:
|
||||||
# return []
|
# return []
|
||||||
@ -44,6 +49,8 @@ class TodoDatabase:
|
|||||||
if "recurring" not in self.database:
|
if "recurring" not in self.database:
|
||||||
return []
|
return []
|
||||||
return self.database["recurring"]
|
return self.database["recurring"]
|
||||||
|
if "recurring" in self.database:
|
||||||
|
return self.database[date] + self.database['recurring']
|
||||||
return self.database[date]
|
return self.database[date]
|
||||||
|
|
||||||
def _update_quotes(self):
|
def _update_quotes(self):
|
||||||
|
@ -12,6 +12,7 @@ from .database import TodoDatabase
|
|||||||
from .thermal_print import ThermalPrinter
|
from .thermal_print import ThermalPrinter
|
||||||
from .sync_calendar import SyncData
|
from .sync_calendar import SyncData
|
||||||
from .tododatatypes import *
|
from .tododatatypes import *
|
||||||
|
from .scheduler_process import run_continuously
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
@ -23,6 +24,8 @@ auth = VerifyToken()
|
|||||||
data = TodoDatabase()
|
data = TodoDatabase()
|
||||||
calendar = SyncData()
|
calendar = SyncData()
|
||||||
printer = ThermalPrinter(data)
|
printer = ThermalPrinter(data)
|
||||||
|
|
||||||
|
stop_run_continuously = run_continuously()
|
||||||
# printer.print_default() #temp debug
|
# printer.print_default() #temp debug
|
||||||
# printer.print_custom("Configuration Site: \n\n")
|
# printer.print_custom("Configuration Site: \n\n")
|
||||||
# printer.print_qrcode()
|
# printer.print_qrcode()
|
||||||
@ -230,6 +233,11 @@ def write_todos(todos: TodoList, auth_result: str = Security(auth.verify)):
|
|||||||
# return {"result": "success"}
|
# return {"result": "success"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/todos/remove_recurring")
|
||||||
|
def remove_recurring_todo(todo: Todo, auth_result: str = Security(auth.verify)):
|
||||||
|
data.remove_recurring(todo)
|
||||||
|
return {"status": "success"}
|
||||||
|
|
||||||
@app.post("/api/todos/print")
|
@app.post("/api/todos/print")
|
||||||
def print_todos(action: PrintAction, auth_result: str = Security(auth.verify)):
|
def print_todos(action: PrintAction, auth_result: str = Security(auth.verify)):
|
||||||
"""A valid access token is required to access this route"""
|
"""A valid access token is required to access this route"""
|
||||||
|
29
application/scheduler_process.py
Normal file
29
application/scheduler_process.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
import schedule
|
||||||
|
|
||||||
|
|
||||||
|
def run_continuously(interval=1):
|
||||||
|
"""Continuously run, while executing pending jobs at each
|
||||||
|
elapsed time interval.
|
||||||
|
@return cease_continuous_run: threading. Event which can
|
||||||
|
be set to cease continuous run. Please note that it is
|
||||||
|
*intended behavior that run_continuously() does not run
|
||||||
|
missed jobs*. For example, if you've registered a job that
|
||||||
|
should run every minute and you set a continuous run
|
||||||
|
interval of one hour then your job won't be run 60 times
|
||||||
|
at each interval but only once.
|
||||||
|
"""
|
||||||
|
cease_continuous_run = threading.Event()
|
||||||
|
|
||||||
|
class ScheduleThread(threading.Thread):
|
||||||
|
@classmethod
|
||||||
|
def run(cls):
|
||||||
|
while not cease_continuous_run.is_set():
|
||||||
|
schedule.run_pending()
|
||||||
|
time.sleep(interval)
|
||||||
|
|
||||||
|
continuous_thread = ScheduleThread()
|
||||||
|
continuous_thread.start()
|
||||||
|
return cease_continuous_run
|
@ -538,6 +538,8 @@ function recurringButtonListener(e) {
|
|||||||
this.querySelector("svg").classList.add("text-black")
|
this.querySelector("svg").classList.add("text-black")
|
||||||
this.querySelector("svg").classList.remove("text-lime-600")
|
this.querySelector("svg").classList.remove("text-lime-600")
|
||||||
this.parentElement.parentElement.dataset.recurring = false
|
this.parentElement.parentElement.dataset.recurring = false
|
||||||
|
//make call to with this todo "/api/todos/remove_recurring"
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.querySelector("svg").classList.remove("text-black")
|
this.querySelector("svg").classList.remove("text-black")
|
||||||
|
Loading…
Reference in New Issue
Block a user