Exemple #1
0
The purpose of this example is to show you how you can use the possibilities
offered by the limpyd_jobs models/classes to do advanced things.
"""
from datetime import datetime
import time
import random
import threading
import logging

from limpyd_jobs import STATUSES
from limpyd_jobs.models import BaseJobsModel, Queue, Job
from limpyd_jobs.workers import Worker, logger
from limpyd import model, fields

# start by defining our logger
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)

# we have to plug our models on a database
BaseJobsModel.database.connect(host='localhost', port=6379, db=15)

# we'll use only one queue name
QUEUE_NAME = 'update_fullname'


class MyQueue(Queue):
    """
    A queue that will store the dates of it's first and last successful job
    """
    first_job_date = fields.InstanceHashField()
    last_job_date = fields.InstanceHashField()
offered by the limpyd_jobs models/classes to do advanced things.
"""
from datetime import datetime
import time
import random
import threading
import logging

from limpyd_jobs import STATUSES
from limpyd_jobs.models import Queue, Job, Error
from limpyd_jobs.workers import Worker, logger
from limpyd import model, fields
from limpyd.contrib.database import PipelineDatabase

# start by defining our logger
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)

# we have to plug our models on a database
database = PipelineDatabase(host='localhost', port=6379, db=15)

# we'll use only one queue name
QUEUE_NAME = 'update_fullname'


class ModelConfigMixin(object):
    """
    A simple mixin to use with all our models, defining one for all the
    database and namespace to use.
    """
    database = database
                                BaseJobsModel,
                                Job as LimpydJob,
                                Queue as LimpydQueue,
                                Error as LimpydError,
                            )
from limpyd_jobs.utils import compute_delayed_until
from limpyd_jobs.workers import Worker as LimpydWorker, logger

from core import get_main_limpyd_database

from core.ghpool import ApiError
from core.models import GithubUser

from . import JobRegistry

logger.addHandler(settings.WORKERS_LOGGER_CONFIG['handler'])

BaseJobsModel.use_database(get_main_limpyd_database())

NAMESPACE = 'gim'


class Queue(LimpydQueue):
    namespace = NAMESPACE


class Error(LimpydError):
    namespace = NAMESPACE

    # store the result of the githubapi request and response in case of error
    # they are set by json.dumps