コード例 #1
0
ファイル: inbox-api.py プロジェクト: ivicac/sync-engine
def main(prod, start_syncback, enable_tracer, config, port, enable_profiler):
    """ Launch the Nylas API service. """
    level = os.environ.get("LOGLEVEL", inbox_config.get("LOGLEVEL"))
    configure_logging(log_level=level)

    maybe_enable_rollbar()

    if config is not None:
        config_path = os.path.abspath(config)
        load_overrides(config_path)

    if prod:
        start(port, start_syncback, enable_tracer, enable_profiler)
    else:
        preflight()
        from werkzeug.serving import run_with_reloader

        run_with_reloader(lambda: start(port, start_syncback, enable_tracer,
                                        enable_profiler))
コード例 #2
0
def main(prod, config, process_num, syncback_id, enable_tracer,
         enable_profiler):
    """ Launch the actions syncback service. """
    setproctitle("syncback-{}".format(process_num))

    maybe_enable_rollbar()

    print("Python", sys.version, file=sys.stderr)

    if config is not None:
        config_path = os.path.abspath(config)
        load_overrides(config_path)
    level = os.environ.get("LOGLEVEL", inbox_config.get("LOGLEVEL"))
    configure_logging(log_level=level)
    reconfigure_logging()

    total_processes = int(os.environ.get("SYNCBACK_PROCESSES", 1))

    def start():
        # Start the syncback service, and just hang out forever
        syncback = SyncbackService(syncback_id, process_num, total_processes)

        if enable_profiler:
            inbox_config["DEBUG_PROFILING_ON"] = True

        port = 16384 + process_num
        enable_profiler_api = inbox_config.get("DEBUG_PROFILING_ON")
        frontend = SyncbackHTTPFrontend(port, enable_tracer,
                                        enable_profiler_api)
        frontend.start()

        syncback.start()
        syncback.join()

    if prod:
        start()
    else:
        preflight()
        from werkzeug.serving import run_with_reloader

        run_with_reloader(start)
コード例 #3
0
def main(email_address, reauth, target, provider):
    """ Auth an email account. """
    preflight()

    maybe_enable_rollbar()

    shard_id = target << 48

    with session_scope(shard_id) as db_session:
        account = (db_session.query(Account).filter_by(
            email_address=email_address).first())
        if account is not None and not reauth:
            sys.exit("Already have this account!")

        if not provider:
            provider = provider_from_address(email_address)

            # Resolve unknown providers into either custom IMAP or EAS.
            if provider == "unknown":
                is_imap = raw_input(
                    "IMAP account? [Y/n] ").strip().lower() != "n"
                provider = "custom" if is_imap else "eas"

        auth_handler = handler_from_provider(provider)
        account_data = auth_handler.interactive_auth(email_address)

        if reauth:
            account = auth_handler.update_account(account, account_data)
        else:
            account = auth_handler.create_account(account_data)

        try:
            if auth_handler.verify_account(account):
                db_session.add(account)
                db_session.commit()
        except NotSupportedError as e:
            sys.exit(str(e))

    print("OK. Authenticated account for {}".format(email_address))
コード例 #4
0
def main(prod, config):
    """ Launch the contact search index service. """
    level = os.environ.get("LOGLEVEL", inbox_config.get("LOGLEVEL"))
    configure_logging(log_level=level)

    maybe_enable_rollbar()

    if config is not None:
        from inbox.util.startup import load_overrides

        config_path = os.path.abspath(config)
        load_overrides(config_path)

    # import here to make sure config overrides are loaded
    from inbox.transactions.search import ContactSearchIndexService

    if not prod:
        preflight()

    contact_search_indexer = ContactSearchIndexService()

    contact_search_indexer.start()
    contact_search_indexer.join()
コード例 #5
0
ファイル: inbox-start.py プロジェクト: ivicac/sync-engine
def main(prod, enable_tracer, enable_profiler, config, process_num,
         exit_after):
    """ Launch the Nylas sync service. """
    level = os.environ.get("LOGLEVEL", inbox_config.get("LOGLEVEL"))
    configure_logging(log_level=level)
    reconfigure_logging()

    maybe_enable_rollbar()

    if config is not None:
        from inbox.util.startup import load_overrides

        config_path = os.path.abspath(config)
        load_overrides(config_path)

    if not prod:
        preflight()

    total_processes = int(os.environ.get("MAILSYNC_PROCESSES", 1))

    setproctitle.setproctitle("sync-engine-{}".format(process_num))

    log = get_logger()
    log.info(
        "start",
        components=["mail sync", "contact sync", "calendar sync"],
        host=platform.node(),
        process_num=process_num,
        total_processes=total_processes,
        recursion_limit=sys.getrecursionlimit(),
    )

    print(banner, file=sys.stderr)
    print(file=sys.stderr)
    print("Python", sys.version, file=sys.stderr)

    if enable_profiler:
        inbox_config["DEBUG_PROFILING_ON"] = True

    port = 16384 + process_num
    enable_profiler_api = inbox_config.get("DEBUG_PROFILING_ON")

    process_identifier = "{}:{}".format(platform.node(), process_num)

    if exit_after:
        exit_after = exit_after.split(":")
        exit_after_min, exit_after_max = int(exit_after[0]), int(exit_after[1])
    else:
        exit_after_min, exit_after_max = None, None

    sync_service = SyncService(
        process_identifier,
        process_num,
        exit_after_min=exit_after_min,
        exit_after_max=exit_after_max,
    )
    signal.signal(signal.SIGTERM, sync_service.stop)
    signal.signal(signal.SIGINT, sync_service.stop)
    http_frontend = SyncHTTPFrontend(sync_service, port, enable_tracer,
                                     enable_profiler_api)
    sync_service.register_pending_avgs_provider(http_frontend)
    http_frontend.start()

    sync_service.run()

    print("\033[94mNylas Sync Engine exiting...\033[0m", file=sys.stderr)