# Path: celeryapp/crawl_tasks.py
# def request(self, dict_item, **kwargs):
# def request_priority(self, dict_item, **kwargs):
# def parse(self, dict_item, **kwargs):
# def parse_priority(self, dict_item, **kwargs):
# def pipeline(self, dict_item, **kwargs):
# def schedule(self, tasks=None, check_task=False, save_filter=False):
# def crawl_synchronous(self, dict_item, **kwargs):


import sys
import os
import socket
import logging
from celeryapp.crawl_tasks import app
from random import randint
# -*- coding: utf-8 -*-
from __future__ import absolute_import

current_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(current_path)
root = os.path.join(current_path, '..')
sys.path.append(root)


LOG = logging
def run_worker(name=None, logging_level='error',
               concurrency='100', pool='gevent',
               queue='default', sort_time_limit='10'):
    if not name:
        name = '%s_%s_%d' % (socket.getfqdn(), queue, randint(10, 99))

    argv = ['worker', 
            '-n', name,  # node name
            '-l', logging_level,
            '-P', pool,  # concurrency pool: pre_fork, thread, eventlet, gevent
            '-c', concurrency,
            '-Q', queue,
            #'--soft-time-limit', sort_time_limit,
            '-D',
            '-f', os.path.join(root, 'logs/%s.log' % name),
            '--pidfile=%s' % os.path.join(root, 'pids/%s.pid' % name)]


# Path: celeryapp/crawl_tasks.py
# def request(self, dict_item, **kwargs):
# def request_priority(self, dict_item, **kwargs):
# def parse(self, dict_item, **kwargs):
# def parse_priority(self, dict_item, **kwargs):
# def pipeline(self, dict_item, **kwargs):
# def schedule(self, tasks=None, check_task=False, save_filter=False):
# def crawl_synchronous(self, dict_item, **kwargs):


# Path: bin/start_celery.py
import sys
import os
import socket
import logging
from celeryapp.crawl_tasks import app
from random import randint

# -*- coding: utf-8 -*-
from __future__ import absolute_import

current_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(current_path)
root = os.path.join(current_path, '..')
sys.path.append(root)


LOG = logging
def run_worker(name=None, logging_level='error',
               concurrency='100', pool='gevent',
               queue='default', sort_time_limit='10'):
    if not name:
        name = '%s_%s_%d' % (socket.getfqdn(), queue, randint(10, 99))

    argv = ['worker', 
            '-n', name,  # node name
            '-l', logging_level,
            '-P', pool,  # concurrency pool: pre_fork, thread, eventlet, gevent
            '-c', concurrency,
            '-Q', queue,
            #'--soft-time-limit', sort_time_limit,
            '-D',
            '-f', os.path.join(root, 'logs/%s.log' % name),
            '--pidfile=%s' % os.path.join(root, 'pids/%s.pid' % name)]


    app.worker_main(argv)