diff --git a/README.md b/README.md index 1d13c21..f8ba4c4 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ Arguments passed to the process or set via environment variables are split into | --api-keys-remote | Use this remote endpoint to query for valid API keys instead of using the local database | `Empty (use local db instead)` | LT_API_KEYS_REMOTE | | --get-api-key-link | Show a link in the UI where to direct users to get an API key | `Empty (no link shown on web ui)` | LT_GET_API_KEY_LINK | | --shared-storage | Shared storage URI to use for multi-process data sharing (e.g. when using gunicorn) | `memory://` | LT_SHARED_STORAGE | +| --secondary | Mark this instance as a secondary instance to avoid conflicts with the primary node in multi-node setups | `Primary node` | LT_SECONDARY | | --load-only | Set available languages | `Empty (use all from argostranslate)` | LT_LOAD_ONLY | | --threads | Set number of threads | `4` | LT_THREADS | | --metrics-auth-token | Protect the /metrics endpoint by allowing only clients that have a valid Authorization Bearer token | `Empty (no auth required)` | LT_METRICS_AUTH_TOKEN | diff --git a/libretranslate/default_values.py b/libretranslate/default_values.py index 2231a70..2c79611 100644 --- a/libretranslate/default_values.py +++ b/libretranslate/default_values.py @@ -156,6 +156,11 @@ _default_options_objects = [ 'default_value': 'memory://', 'value_type': 'str' }, + { + 'name': 'SECONDARY', + 'default_value': False, + 'value_type': 'bool' + }, { 'name': 'LOAD_ONLY', 'default_value': None, diff --git a/libretranslate/main.py b/libretranslate/main.py index a342710..b6b6a03 100644 --- a/libretranslate/main.py +++ b/libretranslate/main.py @@ -154,6 +154,12 @@ def get_args(): metavar="", help="Shared storage URI to use for multi-process data sharing (e.g. via gunicorn)", ) + parser.add_argument( + "--secondary", + default=DEFARGS['SECONDARY'], + action="store_true", + help="Mark this instance as a secondary instance to avoid conflicts with the primary node in multi-node setups", + ) parser.add_argument( "--load-only", type=operator.methodcaller("split", ","), diff --git a/libretranslate/scheduler.py b/libretranslate/scheduler.py index 932718e..836a3ea 100644 --- a/libretranslate/scheduler.py +++ b/libretranslate/scheduler.py @@ -13,10 +13,10 @@ def setup(args): if scheduler is None: scheduler = BackgroundScheduler() - if args.req_flood_threshold > 0: + if not args.secondary and args.req_flood_threshold > 0: scheduler.add_job(func=forgive_banned, trigger="interval", minutes=10) - if args.api_keys and args.require_api_key_secret: + if not args.secondary and args.api_keys and args.require_api_key_secret: scheduler.add_job(func=rotate_secrets, trigger="interval", minutes=30) scheduler.start()