isso.queue.tasks -> isso.tasks

pull/108/head
Martin Zimmermann 10 years ago
parent c9ff66e172
commit 8d2b4b4584

@ -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)

@ -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"]

Loading…
Cancel
Save