mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-19 02:17:38 +03:00
Added support for comments in kill switches
This commit is contained in:
parent
f10cd9d70f
commit
d5b62d957b
@ -6,18 +6,18 @@ EDMarketConnector implements a Kill Switch system that allows us to disable feat
|
||||
|
||||
Killswitches are stored in a JSON file that is queried by EDMC on startup. The format is as follows:
|
||||
|
||||
| Key | Type | Description |
|
||||
| --------------: | :-----: | :------------------------------------------------------------ |
|
||||
| `version` | integer | the version of the Kill Switch JSON file, always 1 |
|
||||
| `last_updated` | string | When last the kill switches were updated (for human use only) |
|
||||
| `kill_switches` | array | The kill switches this file contains (expanded below) |
|
||||
| Key | Type | Description |
|
||||
| --------------: | :------: | :------------------------------------------------------------ |
|
||||
| `version` | `int` | the version of the Kill Switch JSON file, always 1 |
|
||||
| `last_updated` | `string` | When last the kill switches were updated (for human use only) |
|
||||
| `kill_switches` | `array` | The kill switches this file contains (expanded below) |
|
||||
|
||||
The `kill_switches` array contains kill switch objects. Each contains two fields:
|
||||
|
||||
| Key | Type | Description |
|
||||
| --------: | :----------------: | :---------------------------------------------------------------------- |
|
||||
| `version` | `semantic version` | The version of EDMC these kill switches apply to (Must be valid semver) |
|
||||
| `kills` | array of strings | The different keys to disable |
|
||||
| `kills` | `Dict[str, str]` | The different keys to disable, and the reason for the disable |
|
||||
An example follows:
|
||||
|
||||
```json
|
||||
@ -27,7 +27,9 @@ An example follows:
|
||||
"kill_switches": [
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"kills": ["plugins.eddn.send"]
|
||||
"kills": {
|
||||
"plugins.eddn.send": "some reason"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""Fetch kill switches from EDMC Repo."""
|
||||
from typing import Dict, List, NamedTuple, Optional, Union, cast
|
||||
from typing import Dict, List, NamedTuple, Optional, Tuple, Union, cast
|
||||
|
||||
import requests
|
||||
import semantic_version
|
||||
@ -19,7 +19,14 @@ class KillSwitch(NamedTuple):
|
||||
"""One version's set of kill switches."""
|
||||
|
||||
version: semantic_version.Version
|
||||
kills: List[str]
|
||||
kills: Dict[str, str]
|
||||
|
||||
|
||||
class DisabledResult(NamedTuple):
|
||||
"""DisabledResult is the result returned from various is_disabled calls."""
|
||||
|
||||
disbled: bool
|
||||
reason: str
|
||||
|
||||
|
||||
class KillSwitchSet:
|
||||
@ -28,7 +35,7 @@ class KillSwitchSet:
|
||||
def __init__(self, kill_switches: List[KillSwitch]) -> None:
|
||||
self.kill_switches = kill_switches
|
||||
|
||||
def is_disabled(self, id: str, *, version=_current_version) -> bool:
|
||||
def is_disabled(self, id: str, *, version=_current_version) -> DisabledResult:
|
||||
"""
|
||||
Return whether or not the given feature ID is disabled by a killswitch for the given version.
|
||||
|
||||
@ -40,9 +47,9 @@ class KillSwitchSet:
|
||||
if version != ks.version:
|
||||
continue
|
||||
|
||||
return id in ks.kills
|
||||
return DisabledResult(id in ks.kills, ks.kills.get(id, ""))
|
||||
|
||||
return False
|
||||
return DisabledResult(False, "")
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return a string representation of KillSwitchSet."""
|
||||
@ -111,7 +118,7 @@ def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]:
|
||||
logger.warning(f'could not parse killswitch idx {idx}: {e}')
|
||||
continue
|
||||
|
||||
ks = KillSwitch(version=ver, kills=cast(List[str], ks_data['kills']))
|
||||
ks = KillSwitch(version=ver, kills=cast(Dict[str, str], ks_data['kills']))
|
||||
out.append(ks)
|
||||
|
||||
return out
|
||||
@ -148,7 +155,7 @@ def setup_main_list():
|
||||
active = KillSwitchSet(parse_kill_switches(data))
|
||||
|
||||
|
||||
def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> bool:
|
||||
def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> DisabledResult:
|
||||
"""
|
||||
Query the global KillSwitchSet for whether or not a given ID is disabled.
|
||||
|
||||
|
@ -127,8 +127,8 @@ class EDDN:
|
||||
:param cmdr: the CMDR to use as the uploader ID
|
||||
:param msg: the payload to send
|
||||
"""
|
||||
if killswitch.is_disabled('plugins.eddn.send'):
|
||||
logger.warning("eddn.send has been disabled via killswitch. Returning")
|
||||
if (res := killswitch.is_disabled('plugins.eddn.send')).disbled:
|
||||
logger.warning(f"eddn.send has been disabled via killswitch. Returning. ({res.reason})")
|
||||
return
|
||||
|
||||
uploader_id = cmdr
|
||||
|
@ -511,8 +511,10 @@ def worker() -> None:
|
||||
|
||||
retrying = 0
|
||||
while retrying < 3:
|
||||
if killswitch.is_disabled("plugins.edsm.worker"):
|
||||
logger.warning('EDSM worker has been disabled via kill switch. Not uploading data.')
|
||||
if (res := killswitch.is_disabled("plugins.edsm.worker")).disbled:
|
||||
logger.warning(
|
||||
f'EDSM worker has been disabled via kill switch. Not uploading data. ({res.reason})'
|
||||
)
|
||||
break
|
||||
try:
|
||||
if TYPE_CHECKING:
|
||||
|
@ -1203,8 +1203,8 @@ def new_worker():
|
||||
logger.debug('Starting...')
|
||||
while True:
|
||||
events = get_events()
|
||||
if killswitch.is_disabled("plugins.inara.worker"):
|
||||
logger.warning("Inara worker disabled via killswitch")
|
||||
if (res := killswitch.is_disabled("plugins.inara.worker")).disbled:
|
||||
logger.warning(f"Inara worker disabled via killswitch. ({res.reason})")
|
||||
continue
|
||||
|
||||
for creds, event_list in events.items():
|
||||
|
Loading…
x
Reference in New Issue
Block a user