Example #1
0
def _start_fetcher_processes():
    procs = find_fetcher_processes()

    # fetcher processes are started by groups
    cfg = cfg4py.get_instance()
    for fetcher in cfg.quotes_fetchers:
        impl = fetcher.get("impl")
        workers = fetcher.get("workers")

        ports = [3181 + i for i in range(len(workers))]
        for group in workers:
            sessions = group.get("sessions")
            port = group.get("port") or ports.pop()
            account = group.get("account")
            password = group.get("password")
            started_sessions = procs.get(f"{impl}:{port}", [])
            if sessions - len(started_sessions) > 0:
                print(f"启动的{impl}实例少于配置要求(或尚未启动),正在启动中。。。")
                # sanic manages sessions, so we have to restart it as a whole
                for pid in started_sessions:
                    try:
                        os.kill(pid, signal.SIGTERM)
                    except Exception:
                        pass

                _start_fetcher(impl, account, password, port, sessions)
                time.sleep(1)

    time.sleep(3)
    show_fetcher_processes()
Example #2
0
 async def init(self):
     cfg = cfg4py.get_instance()
     for i, name in enumerate(self.databases):
         db = await aioredis.create_redis_pool(cfg.redis.dsn,
                                               encoding="utf-8",
                                               maxsize=2,
                                               db=i)
         await self.sanity_check(db)
         await db.set("__meta__.database", name)
         setattr(self, name, db)
Example #3
0
async def init(fetcher=None):
    """初始化omicron

    Args:
        fetcher: instance of AbstractQuotesFetcher。如果不为None,则Omicron会使用这个fetcher
        来获取行情数据,否则使用远程接口。

    Returns:

    """
    # to avoid circular import
    from .models.securities import Securities

    global _local_fetcher, cache
    _local_fetcher = fetcher

    await cache.init()
    secs = Securities()
    await secs.load()

    cfg = cfg4py.get_instance()
    if cfg.postgres.enabled:
        await init_db(cfg.postgres.dsn)
Example #4
0
 async def create_quotes_fetcher(self):
     cfg: Config = cfg4py.get_instance()
     fetcher_info = cfg.quotes_fetchers[0]
     impl = fetcher_info["impl"]
     params = fetcher_info["workers"][0]
     await aq.create_instance(impl, **params)
Example #5
0
from omicron import cache
from omicron.core.timeframe import tf
from omicron.core.types import FrameType
from omicron.models.securities import Securities
from pyemit import emit

import omega.core.sanity
import omega.jobs
import omega.jobs.sync as sync
from omega.config.schema import Config
from omega.core.events import Events, ValidationError
from omega.fetcher.abstract_quotes_fetcher import AbstractQuotesFetcher as aq
from tests import init_test_env, start_omega

logger = logging.getLogger(__name__)
cfg: Config = cfg4py.get_instance()


class TestJobs(unittest.IsolatedAsyncioTestCase):
    async def asyncSetUp(self) -> None:
        init_test_env()

        await emit.start(engine=emit.Engine.REDIS, dsn=cfg.redis.dsn, start_server=True)

        await self.create_quotes_fetcher()
        await omicron.init(aq)
        home = Path(cfg.omega.home).expanduser()
        os.makedirs(str(home / "data/chksum"), exist_ok=True)

        self.omega = await start_omega()
Example #6
0
def has_db():
    return cfg4py.get_instance().postgres.enabled
Example #7
0
 async def asyncSetUp(self) -> None:
     init_test_env()
     self.cfg = cfg4py.get_instance()
     self.omega = await start_omega()
     self.archive = await start_archive_server()
     await omicron.init()
Example #8
0
import logging
import pickle
import unittest

import aiohttp
import arrow
import cfg4py
import omicron

from omega import __version__
from tests import init_test_env, start_archive_server, start_omega

logger = logging.getLogger(__name__)
cfg = cfg4py.get_instance()


class TestWebInterfaces(unittest.IsolatedAsyncioTestCase):
    async def asyncSetUp(self) -> None:
        init_test_env()
        self.cfg = cfg4py.get_instance()
        self.omega = await start_omega()
        self.archive = await start_archive_server()
        await omicron.init()

    async def asyncTearDown(self) -> None:
        if self.omega:
            self.omega.kill()
        if self.archive:
            self.archive.kill()

    async def server_post(self,
Example #9
0
    def test_005_sigleton(self):
        cfg1 = cfg4py.get_instance()
        cfg2 = cfg4py.get_instance()

        self.assertEqual(id(cfg1), id(cfg2))
Example #10
0
 async def asyncSetUp(self) -> None:
     init_test_env()
     self.cfg = cfg4py.get_instance()
     self.omega = await start_omega()