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)
from inbox.auth.microsoft import MicrosoftAccountData, MicrosoftAuthHandler from inbox.models import Account, Namespace from inbox.models.backends.generic import GenericAccount from inbox.models.backends.gmail import GOOGLE_EMAIL_SCOPE, GmailAccount from inbox.models.backends.outlook import OutlookAccount from inbox.models.secret import SecretType from inbox.models.session import global_session_scope from inbox.util.logging_helper import reconfigure_logging from inbox.webhooks.gpush_notifications import app as webhooks_api app = Flask(__name__) # Handle both /endpoint and /endpoint/ without redirecting. # Note that we need to set this *before* registering the blueprint. app.url_map.strict_slashes = False reconfigure_logging() @app.errorhandler(APIException) def handle_input_error(error): response = jsonify(message=error.message, type="invalid_request_error") response.status_code = error.status_code return response def default_json_error(ex): """ Exception -> flask JSON responder """ logger = get_logger() logger.error("Uncaught error thrown by Flask/Werkzeug", exc_info=ex) response = jsonify(message=str(ex), type="api_error") response.status_code = ex.code if isinstance(ex, HTTPException) else 500
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)