Example #1
0
from tools.date_json_encoder import CJsonEncoder
from tools.date_utils import DateUtils
from source.async_redis import AsyncRedis
from source.async_model import AsyncModelBase
# from source.redisbase import RedisBase
from source.properties import Properties
from .report import Report
import sys
import traceback

logger = Logs().logger
properties = Properties('task')
redis = AsyncRedis()
date_utils = DateUtils()

task_queue = properties.get('cache', 'task_queue')
failed_queue = properties.get('cache', 'failed_queue')
loop_num = int(properties.get('task', 'task_num'))
server_key = properties.get('cache', 'servers')
server_coroutine_key = properties.get('cache', 'server_coroutine')


async def save_to_db(task_unique_id, service_path, method, params_json):
    """
    保存任务到DB
    :param task_unique_id:
    :param service_path:
    :param method:
    :param params_json:
    :return:
    """
Example #2
0
# -*- coding:utf-8 -*-
"""
@package:
@file: aio_redis.py
@author: yuiitsu
@time: 2020-04-03 19:48
"""
import ssl
import aioredis
from source.properties import Properties
from tools.logs import Logs

properties = Properties()
logger = Logs().logger

REDIS_HOST = properties.get("redis", "REDIS_HOST")
REDIS_PORT = int(properties.get('redis', 'REDIS_PORT'))
REDIS_PASS = properties.get('redis', 'REDIS_PASS')
REDIS_USE_SSL = properties.get('redis', 'REDIS_USE_SSL')
REDIS_MAX_CONNECTION = int(properties.get('redis', 'REDIS_MAX_CONNECTION'))
SSLContext = ssl.SSLContext(
) if REDIS_USE_SSL and REDIS_USE_SSL == 'True' else False


class AsyncRedis:
    async def get_conn(self):
        """
        获取连接
        :return:
        """
        redis = await aioredis.create_redis((REDIS_HOST, REDIS_PORT),
Example #3
0
from tools.logs import Logs
from tools.date_json_encoder import CJsonEncoder
from tools.date_utils import DateUtils
from source.async_redis import AsyncRedis
# from source.redisbase import RedisBase
from source.properties import Properties
from .report import Report
import sys
import traceback

logger = Logs().logger
properties = Properties('task')
redis = AsyncRedis()
date_utils = DateUtils()

task_queue = properties.get('cache', 'task_queue')
failed_queue = properties.get('cache', 'failed_queue')
loop_num = int(properties.get('task', 'task_num'))


async def add(path='',
              method='',
              arguments=None,
              is_priority=False,
              sub_task=None):
    """
    添加任务
    :param path: 调用包文件路径
    :param method:  调用方法
    :param arguments: 请求参数
    :param is_priority: 是否优先处理(True or False)
Example #4
0
from constants.cachekey_predix import CacheKeyPredix as cachekey
from source.redisbase import RedisBase
from source.service_manager import ServiceManager
from tools.schedule_utils import ScheduleUtils
from tools.date_json_encoder import CJsonEncoder
from source.properties import Properties
from source.model import ModelBase
from tools.date_utils import DateUtils
import traceback
from tools.logs import Logs

properties = Properties()

pool_size = 3
try:
    pool_size = int(properties.get('task', 'POOL_NUM'))
except Exception, e:
    print e

redis = RedisBase()
task_redis = redis.get_conn()
error_redis = redis.get_conn()
cache_key = cachekey.TASK_DATA_LIST
error_cache_key = cachekey.ERROR_TASK_DATA_LIST
pool = threadpool.ThreadPool(pool_size)
service_manager = ServiceManager()
config = config
logger = Logs().get_logger()


def update_task(last_id):
Example #5
0
from constants.cachekey_predix import CacheKeyPredix as cachekey
from source.redisbase import RedisBase
from source.service_manager import ServiceManager
from tools.schedule_utils import ScheduleUtils
from tools.date_json_encoder import CJsonEncoder
from source.properties import Properties
from source.model import ModelBase
from tools.date_utils import DateUtils
import traceback
from tools.logs import Logs

properties = Properties()

pool_size = 3
try:
    pool_size = int(properties.get('task', 'POOL_NUM'))
except Exception, e:
    print e

redis = RedisBase()
task_redis = redis.get_conn()
error_redis = redis.get_conn()
cache_key = cachekey.TASK_DATA_LIST
error_cache_key = cachekey.ERROR_TASK_DATA_LIST
pool = threadpool.ThreadPool(pool_size)
service_manager = ServiceManager()
config = config
logger = Logs().get_logger()


def update_task(last_id):
Example #6
0
from source.async_redis import AsyncRedis
from tools.date_json_encoder import CJsonEncoder
from tools.date_utils import DateUtils
from tools.logs import Logs
from tools.cron_utils import CronUtils
from source.properties import Properties
from task.schedule.path_conf import CONF
import task

# redis = RedisBase()
redis = AsyncRedis()
logger = Logs().logger
cron_utils = CronUtils()
properties = Properties('schedule')

intervals = int(properties.get('schedule', 'intervals'))
run_time = int(properties.get('schedule', 'run_time'))
SCHEDULE_KEY = properties.get('schedule', 'schedule_key')
JOB_KEY = properties.get('schedule', 'job_key')
key_YYMMDDHHMM = '%Y%m%d%H%M'
key_YYMMDDHHMMSS = '%Y%m%d%H%M%S'


async def do_job_list(job_list, is_normal=True):
    """
    开协程执行定时任务
    job_list 需要执行的任务列表
    is_normal 是否正常执行任务  True正常任务 ,  False 过期任务补偿执行
    :return: 
    """
    for job in job_list:
Example #7
0
# -*- coding:utf-8 -*-
"""
@author: delu
@file: __init__.py.py
@time: 18/6/20 14:07
"""
import importlib

from source.properties import Properties
from tools.cron_utils import CronUtils
from tools.date_utils import DateUtils
from constants.error_code import Code

cron_utils = CronUtils()
properties = Properties('schedule')
SCHEDULE_KEY = properties.get('schedule', 'schedule_key')
JOB_KEY = properties.get('schedule', 'job_key')
RUN_TIME = int(properties.get('schedule', 'run_time'))


async def async_add_job(service_path='',
                        method='',
                        params={},
                        start_time='',
                        cron='',
                        job_id='',
                        group_name='default',
                        repeat_count=0):
    """
    添加定时任务
    :param service_path:   需要执行的service路径