diff --git a/app/templates/tasks.html b/app/templates/tasks.html
index e7f0db8..f403efd 100644
--- a/app/templates/tasks.html
+++ b/app/templates/tasks.html
@@ -6,13 +6,24 @@
{% for task in tasks %}
{% set createdTime = datetime.fromtimestamp(task.created_timestamp) %}
{% set createdTime = datetime.strptime(str(createdTime), '%Y-%m-%d %H:%M:%S') %}
+ {% set createdTime = createdTime.astimezone(ZoneInfo(current_user.timezone)) %}
{{ task.title }}
{% if task.description != None %}
- {{ task.description }}
+ {% set description = task.description %}
+ {% set url_regex = '(https?://[^\s]+)' %}
+
+ {% set match = re.search(url_regex, description) %}
+ {% if match %}
+ {% set url = match.group(0) %}
+ {% set rest = description[match.end(0):] %}
+ {{ description[:match.start(0)] }}{{ url }}{{ rest }}
+ {% else %}
+
{{ description }}
+ {% endif %}
{% endif %}
diff --git a/app/worker.py b/app/worker.py
index 288a29e..6e1e617 100644
--- a/app/worker.py
+++ b/app/worker.py
@@ -1,9 +1,11 @@
+from celery import Celery
+from celery.schedules import crontab
+from create_events import createEvents
+from cleanup_events import cleanupEvents
import os
from flask import Flask
from misc import currDay, datetime, time, timedelta
from db import db, Period, Event
-from create_events import createEvents
-from apscheduler.schedulers.background import BlockingScheduler
basedir = os.path.abspath(os.path.dirname(__file__))
@@ -18,18 +20,33 @@ app.config['SQLALCHEMY_DATABASE_URI'] =\
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
-# Define function to run create_events with app context
-def run_create_events():
+redis_url = 'redis://' + \
+ os.environ['REDIS_HOST'] + \
+ ':' + os.environ['REDIS_PORT'] + \
+ '/' + os.environ['REDIS_DBNUM']
+
+celerymsg = Celery('tasks', backend=redis_url, broker=redis_url)
+
+# Task definitions
+@celerymsg.task
+def runCreateEvents():
with app.app_context():
createEvents(db, currDay, Period, Event)
-# Call createEvents on initial launch of the script
-run_create_events()
+def runCleanupEvents():
+ with app.app_context():
+ cleanupEvents(db, Event)
-
-# Set up scheduler to run function at 59th minute of every hour
-scheduler = BlockingScheduler()
-scheduler.add_job(run_create_events, 'cron', minute=59)
-
-# Start scheduler
-scheduler.start()
\ No newline at end of file
+# Scheduled tasks
+celerymsg.conf.beat_schedule = {
+ 'hourly-createevents': {
+ 'task': 'worker.runCreateEvents',
+ # Run hourly
+ 'schedule': crontab(hour="*", minute="59"),
+ },
+ 'monthly-cleanupevents': {
+ 'task': 'worker.runCleanupEvents',
+ # Run monthly
+ 'schedule': crontab(day_of_month="29")
+ }
+}
\ No newline at end of file
diff --git a/docker-compose.yaml b/docker-compose.yaml
index c811c2a..600d3dc 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -9,31 +9,43 @@ services:
- MYSQL_HOST=db
- MYSQL_PORT=3306
- MYSQL_DB=bellscheduler
+ - REDIS_HOST=redis
+ - REDIS_PORT=6379
+ - REDIS_DBNUM=0
- SECRET_KEY=notasecuresecretkeyonlyuseforlocaldevelopment
- NODE_NAME=local
- POD_NAME=local
- FLASK_ENV=development
- FLASK_DEBUG=1
- PYTHONUNBUFFERED=1
+ - SIGNUP_ENABLED=YES
ports:
- 127.0.0.1:80:80
worker:
image: container-registry.infra.dubyatp.xyz/bellscheduler/app:latest-testing
restart: always
- entrypoint: python3
- command: "-m worker"
+ entrypoint: celery
+ command: "-A worker.celerymsg worker --loglevel=DEBUG -B"
environment:
- MYSQL_USER=root
- MYSQL_PASSWORD=notasecuresecretkeyonlyuseforlocaldevelopment
- MYSQL_HOST=db
- MYSQL_PORT=3306
- MYSQL_DB=bellscheduler
+ - REDIS_HOST=redis
+ - REDIS_PORT=6379
+ - REDIS_DBNUM=0
- SECRET_KEY=notasecuresecretkeyonlyuseforlocaldevelopment
- NODE_NAME=local
- POD_NAME=local
- FLASK_ENV=development
- FLASK_DEBUG=1
- PYTHONUNBUFFERED=1
+ redis:
+ image: redis:7.0.10-alpine3.17
+ restart: always
+ ports:
+ - 127.0.0.1:6379:6379
db:
image: mariadb:10.7.8-focal
restart: always