mirror of https://github.com/kianby/stacosys
remove cron tasks
parent
185641e6d0
commit
5f28274706
@ -1,38 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import sqlite3
|
||||
import datetime
|
||||
from ulid import ULID
|
||||
|
||||
# add column ulid
|
||||
connection = sqlite3.connect("db.sqlite")
|
||||
cursor = connection.cursor()
|
||||
script = """
|
||||
PRAGMA foreign_keys = OFF;
|
||||
BEGIN TRANSACTION;
|
||||
ALTER TABLE comment ADD ulid INTEGER;
|
||||
COMMIT;
|
||||
PRAGMA foreign_keys = ON;
|
||||
"""
|
||||
cursor.executescript(script)
|
||||
connection.close()
|
||||
|
||||
# fill in ulid column
|
||||
connection = sqlite3.connect("db.sqlite")
|
||||
cursor = connection.cursor()
|
||||
updates = []
|
||||
for row in cursor.execute('SELECT * FROM comment'):
|
||||
row_id = row[0]
|
||||
string_created = row[2]
|
||||
date_created = datetime.datetime.strptime(string_created, "%Y-%m-%d %H:%M:%S")
|
||||
ulid = ULID.from_datetime(date_created)
|
||||
update = "UPDATE comment SET ulid = " + str(int(ulid)) + " WHERE id = " + str(row_id)
|
||||
print(update)
|
||||
updates.append(update)
|
||||
|
||||
for update in updates:
|
||||
pass
|
||||
connection.execute(update)
|
||||
connection.commit()
|
||||
connection.close()
|
@ -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,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…
Reference in New Issue