remove cron tasks
This commit is contained in:
parent
185641e6d0
commit
5f28274706
10 changed files with 50 additions and 148 deletions
|
|
@ -9,7 +9,6 @@ import profig
|
|||
class ConfigParameter(Enum):
|
||||
DB_SQLITE_FILE = "main.db_sqlite_file"
|
||||
LANG = "main.lang"
|
||||
COMMENT_POLLING = "main.newcomment_polling"
|
||||
|
||||
HTTP_HOST = "http.host"
|
||||
HTTP_PORT = "http.port"
|
||||
|
|
@ -24,7 +23,6 @@ class ConfigParameter(Enum):
|
|||
|
||||
SITE_NAME = "site.name"
|
||||
SITE_URL = "site.url"
|
||||
SITE_TOKEN = "site.token"
|
||||
SITE_ADMIN_EMAIL = "site.admin_email"
|
||||
SITE_REDIRECT = "site.redirect"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from stacosys.db import dao
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def submit_new_comment(site_name, mailer):
|
||||
for comment in dao.find_not_notified_comments():
|
||||
comment_list = (
|
||||
"author: %s" % comment.author_name,
|
||||
"site: %s" % comment.author_site,
|
||||
"date: %s" % comment.created,
|
||||
"url: %s" % comment.url,
|
||||
"",
|
||||
"%s" % comment.content,
|
||||
"",
|
||||
)
|
||||
email_body = "\n".join(comment_list)
|
||||
|
||||
# send email to notify admin
|
||||
subject = "STACOSYS %s" % site_name
|
||||
if mailer.send(subject, email_body):
|
||||
logger.debug("new comment processed ")
|
||||
|
||||
# save notification datetime
|
||||
dao.notify_comment(comment)
|
||||
else:
|
||||
logger.warning("rescheduled. send mail failure " + subject)
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
import background
|
||||
from flask import abort, redirect, request
|
||||
|
||||
from stacosys.db import dao
|
||||
|
|
@ -13,7 +13,6 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
@app.route("/newcomment", methods=["POST"])
|
||||
def new_form_comment():
|
||||
|
||||
data = request.form
|
||||
logger.info("form data " + str(data))
|
||||
|
||||
|
|
@ -40,7 +39,10 @@ def new_form_comment():
|
|||
abort(400)
|
||||
|
||||
# add a row to Comment table
|
||||
dao.create_comment(url, author_name, author_site, author_gravatar, message)
|
||||
comment = dao.create_comment(url, author_name, author_site, author_gravatar, message)
|
||||
|
||||
# send notification e-mail asynchronously
|
||||
submit_new_comment(comment)
|
||||
|
||||
return redirect(app.config.get("SITE_REDIRECT"), code=302)
|
||||
|
||||
|
|
@ -51,3 +53,32 @@ def check_form_data(d):
|
|||
return not filtered
|
||||
|
||||
|
||||
@background.task
|
||||
def submit_new_comment(comment):
|
||||
comment_list = (
|
||||
"Web admin interface: %s/web/admin" % app.config.get("SITE_URL"),
|
||||
"",
|
||||
"author: %s" % comment.author_name,
|
||||
"site: %s" % comment.author_site,
|
||||
"date: %s" % comment.created,
|
||||
"url: %s" % comment.url,
|
||||
"",
|
||||
"%s" % comment.content,
|
||||
"",
|
||||
)
|
||||
email_body = "\n".join(comment_list)
|
||||
|
||||
# send email to notify admin
|
||||
subject = "STACOSYS " + app.config.get("SITE_NAME")
|
||||
if app.config.get("MAILER").send(subject, email_body):
|
||||
logger.debug("new comment processed")
|
||||
|
||||
# save notification datetime
|
||||
dao.notify_comment(comment)
|
||||
else:
|
||||
logger.warning("rescheduled. send mail failure " + subject)
|
||||
|
||||
|
||||
@background.callback
|
||||
def submit_new_comment_callback(future):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask_apscheduler import APScheduler
|
||||
from stacosys.interface import app
|
||||
|
||||
|
||||
class JobConfig(object):
|
||||
|
||||
JOBS: list = []
|
||||
|
||||
SCHEDULER_EXECUTORS = {"default": {"type": "threadpool", "max_workers": 1}}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
new_comment_polling_seconds,
|
||||
site_name,
|
||||
mailer,
|
||||
):
|
||||
self.JOBS = [
|
||||
{
|
||||
"id": "submit_new_comment",
|
||||
"func": "stacosys.core.cron:submit_new_comment",
|
||||
"args": [site_name, mailer],
|
||||
"trigger": "interval",
|
||||
"seconds": new_comment_polling_seconds,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def configure(
|
||||
comment_polling,
|
||||
site_name,
|
||||
mailer,
|
||||
):
|
||||
app.config.from_object(
|
||||
JobConfig(
|
||||
comment_polling,
|
||||
site_name,
|
||||
mailer,
|
||||
)
|
||||
)
|
||||
scheduler = APScheduler()
|
||||
scheduler.init_app(app)
|
||||
scheduler.start()
|
||||
Loading…
Add table
Add a link
Reference in a new issue