diff --git a/isso/__init__.py b/isso/__init__.py index f7e8f7b..60149fb 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -67,7 +67,7 @@ try: except ImportError: uwsgi = None -from isso import cache, config, db, migrate, ext, queue, spam, views, wsgi +from isso import cache, config, db, migrate, queue, spam, tasks, views, wsgi from isso.wsgi import origin, urlsplit from isso.utils import http, JSONRequest, html, hash @@ -182,8 +182,9 @@ def make_app(conf): else: cacheobj = cache.SACache(dbobj, threshold=2048) - jobs = queue.Jobs() + jobs = tasks.Jobs() jobs.register("db-purge", dbobj, conf.getint("moderation", "purge-after")) + jobs.register("http-fetch", dbobj) queueobj = queue.Queue(1024) worker = queue.Worker(queueobj, jobs) diff --git a/isso/queue/__init__.py b/isso/queue/__init__.py index c88e14a..6fa78fc 100644 --- a/isso/queue/__init__.py +++ b/isso/queue/__init__.py @@ -2,7 +2,6 @@ from __future__ import unicode_literals, division -import abc import json import logging import threading @@ -12,13 +11,13 @@ import bisect import functools import time -import datetime try: import queue except ImportError: import Queue as queue +from isso.tasks import Cron from isso.compat import iteritems logger = logging.getLogger("isso") @@ -189,56 +188,7 @@ class Worker(threading.Thread): time.sleep(f * Worker.interval) -class Task(object): - - __metaclass__ = abc.ABCMeta - - @abc.abstractmethod - def run(self, data): - return - - @classmethod - def __subclasshook__(cls, subclass): - return cls is Cron - - -class Cron(Task): - - __metaclass__ = abc.ABCMeta - - def __init__(self, *args, **kwargs): - self.timedelta = datetime.timedelta(*args, **kwargs) - - def run(self, data): - return - - -from .tasks import db - - -class Jobs(dict): - """Obviously a poor man's factory""" - - available = { - "db-purge": db.Purge - } - - def __init__(self): - super(Jobs, self).__init__() - - def register(self, name, *args, **kwargs): - if name in self: - return - - try: - cls = Jobs.available[name] - except KeyError: - raise RuntimeError("No such task '%s'" % name) - - self[name] = cls(*args, **kwargs) - - from .sqlite import SQLite3Queue -__all__ = ["Full", "Empty", "Retry", "Timeout", "Message", "Queue", "Targets", - "Task", "Cron", "SQLite3Queue"] +__all__ = ["Full", "Empty", "Retry", "Timeout", "Message", "Queue", + "SQLite3Queue"] diff --git a/isso/queue/tasks/__init__.py b/isso/tasks/__init__.py similarity index 100% rename from isso/queue/tasks/__init__.py rename to isso/tasks/__init__.py diff --git a/isso/queue/tasks/db.py b/isso/tasks/db.py similarity index 100% rename from isso/queue/tasks/db.py rename to isso/tasks/db.py diff --git a/isso/queue/tasks/http.py b/isso/tasks/http.py similarity index 100% rename from isso/queue/tasks/http.py rename to isso/tasks/http.py diff --git a/isso/queue/tasks/mail.py b/isso/tasks/mail.py similarity index 100% rename from isso/queue/tasks/mail.py rename to isso/tasks/mail.py