Beispiel #1
0
def main():
    logger.init_log('apns_agent', 'apns_agent')
    setproctitle('apns:agent')
    svr = IncomingServer(handle_req, log=False)
    svr.bind(parse_ip_port(apns_conf.get('_default', 'host'))[-1])
    svr.start(0)
    IOLoop.instance().start()
Beispiel #2
0
def run_process(redis_url, process_ratio, run_or_not):
    """
    通过load_conf.py读取配置,统一加载

    :param redis_url: 监控redis地址
    :param process_ratio: 启动进程数
    :param run_or_not: 是否启动该进程
    :return:
    """
    host, port, db, pwd, channel = resolve_redis_url(redis_url, True)
    logger_flag = "mq_%s" % channel
    logger.init_log(logger_flag, logger_flag)

    if not (redis_url and isinstance(redis_url, str) and '|' not in redis_url):
        logger.fatal('redis_url invalid: %s' % redis_url)
        return
    if not isinstance(process_ratio, int):
        logger.fatal('process_ratio invalid: %s' % type(process_ratio))
        return
    if not isinstance(run_or_not, int):
        logger.fatal('run param invalid: %s' % type(run_or_not))
        return

    if not run_or_not:
        logger.debug('not run {0} via config'.format(redis_url))
        return
    setproctitle('mq:host:{0}'.format(channel))

    fork_processes(process_ratio)
    options.logging = 'error'
    setproctitle('mq:{0}:{1}'.format(channel, db))

    loop = IOLoop.instance()

    setattr(__builtins__, 'handler_map', {})
    setattr(__builtins__, 'watch_redis',
            AsyncRedis(None, False, host, port, db, pwd))
    setattr(__builtins__, 'watch_channel', channel)
    setattr(__builtins__, 'dev_filter',
            AsyncRedis(redis_conf.get('dev_filter', 'url')))
    setattr(
        __builtins__, 'level_client',
        GeneralInternalClient(
            parse_ip_port(leveldb_conf.get('default', 'host'))))
    setattr(__builtins__, 'account_cache',
            AsyncRedis(redis_conf.get('oauth', 'url')))

    logger.warn('run_process channel:{0}, db:{1}, redis_url={2}'.format(
        channel, db, redis_url))

    # 导入handler模块
    mod_name = '.'.join((channel, 'uni_handler', 'handle_msg'))
    handler = import_object(mod_name)
    logger.warn('import mod:{0}'.format(mod_name))
    if handler:
        logger.warn('found handler={0}'.format(mod_name))
        handler_map.update({channel: handler})

    loop.add_callback(coroutine_run)
    loop.start()
Beispiel #3
0
def main():
    logger.init_log('lvl_core', 'lvl_core')
    setproctitle('lvl:core')
    IncomingServer(handle_req, log=False).listen(
        parse_ip_port(
            dict(conf_load('leveldb.ini')).get('leveldb.ini').get(
                'default', 'host'))[-1])
    IOLoop.instance().start()
Beispiel #4
0
def resolve_port(conf, mode):
    """
    监听端口按照基端口累加
    :param conf: 配置对象
    :param mode: 运行模式
    :return:
    """
    base_port = parse_ip_port(conf.get('_default', 'host'))[-1]
    m = pattern.search(mode)
    if not m:
        return base_port
    return base_port + int(m.groupdict().get('index'))
Beispiel #5
0
def run():
    device_token = 'fe9ffe531afbab4f8f44cf220de67e9c39ddf45874eaaa90559426d002f56a91'
    device_token = '3f24b320810a1ee6de177f2362f7fb6706a84b92e30a1182ee77443d239c634e'
    apns_client = APNsClient(cert_fn,
                             parse_ip_port(conf.get('_apns', compile_type)),
                             v2_encode)
    for i in xrange(10):
        print 'i = ', i
        apns_client.queue_push(
            device_token, {
                'aps': {
                    'alert': 'hello tornado push' + str(i),
                    'badge': 1,
                    'sound': 'Voicemail.caf'
                }
            })
Beispiel #6
0
def queue_push(apns_conf, compile_type, bundle_id, device_token, push_body):
    push_body = msgpack.unpackb(push_body, encoding='utf-8')
    logger.debug('QUEUE: {0}, {1}, {2}, {3}'.format(compile_type, bundle_id,
                                                    device_token, push_body))

    section = ':'.join((compile_type, bundle_id))

    dst_list = apns_clients.get(section)
    if not dst_list or len(dst_list) < APNS_CLIENT_PER_POOL:
        client = APNsClient(
            apns_conf.get(section, 'cert'),
            parse_ip_port(apns_conf.get('_apns', compile_type)), v2_encode)
        apns_clients[section].append(client)
    else:
        client = apns_clients[section][randint(0, APNS_CLIENT_TOP)]

    #从连接池中随机挑一个,或者创建一个新的
    client.queue_push(device_token, push_body)
Beispiel #7
0
#!/usr/bin/python2.7
# coding=utf-8
"""
Created on 2016/5/3

@author: Jay
"""
from util.redis.redis_client import Redis
from util.internal_forward.gen_internal_client import GeneralInternalClient
from setting import CALC_RDS_URI, MQ_DISP_RDS_URI, LEVEL_DB_HOST
from util.convert import parse_ip_port

GCalcRdsInts = Redis(CALC_RDS_URI)
GMQDispRdsInts = Redis(MQ_DISP_RDS_URI)
GLevelDBClient = GeneralInternalClient(parse_ip_port(LEVEL_DB_HOST))
Beispiel #8
0
def main():
    client = APNsClient(cert_fn, parse_ip_port(feedback_host),
                        lambda *args: '')
    client.queue_push(
        '04130e45d6ed9c3429e697e0cbce2ed2f5ac59868de95c281dc1dec83d07f631', '')
Beispiel #9
0
#coding:utf-8

from utils import logger
from util.internal_forward.apple_push_encode import encode as apns_encode
from tornado.gen import coroutine
from util.internal_forward.gen_internal_client import GeneralInternalClient
from util.stream_config_client import load as conf_load
from util.convert import parse_ip_port

apns_client = GeneralInternalClient(
    parse_ip_port(
        dict(conf_load('apns.ini')).get('apns.ini').get('_default', 'host')))


@coroutine
def invoke(push_body, channel_args):
    """
    :param push_body: dict
    """
    try:
        if not (push_body and isinstance(push_body, dict)):
            logger.warn('ios_invoke push_body: {0}'.format(push_body))
            return
        if 3 != len(channel_args):
            logger.warn('invalid ios args: {0}'.format(channel_args))
            return

        alert = push_body.get('description')
        push_body = dict(((k, push_body.get(k)) for k in ('cb', 'f', 'id')))

        r = yield apns_client.forward(