Persist per-channel HLS server selection across sxm.pl restarts#76
Persist per-channel HLS server selection across sxm.pl restarts#76
Conversation
Agent-Logs-Url: https://github.com/paul-1/plugin-SiriusXM/sessions/cbff5d11-90ec-4673-9757-c7e71e8b0c12 Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
|
@copilot When is the cache file updated? Looks like only when the channel data is refreshed. However we could have changed servers in the meantime. We need to update the data when the server change is made. However the channel cache is quite large to be writing for the server change. Perhaps a separate file with the last_server is better. |
Agent-Logs-Url: https://github.com/paul-1/plugin-SiriusXM/sessions/52a5e6ec-1615-4977-a4b0-7597b77abfdb Co-authored-by: paul-1 <6473457+paul-1@users.noreply.github.com>
Good catch. The channel cache is indeed only written during the 24-hour refresh cycle, so embedding server state there means switches that happen between refreshes would be lost on restart. Switched to a dedicated lightweight
|
When
sxm.plrestarts, the per-channel CDN server selection (primary/secondary) was lost, causing channels that had failed over to secondary to reset unnecessarily. This persists the server selection to a dedicated lightweight file (server_state.json) so it survives restarts and is always current.Changes
save_server_state(): Writes only thechannel_serverhash toserver_state.jsonin the same cache directory. Called immediately insideswitch_channel_server()andreset_channel_server()so the file always reflects the current state — not just at the 24-hour channel cache refresh.load_server_state(): Reads and restoreschannel_serveron startup. Backward-compatible — silently skips if the file does not exist yet (e.g. first run or upgrade from an older version).load_server_state()is called at startup alongsideload_channel_cache().channels.jsonunchanged: Server state is no longer embedded in the channel list cache.Original prompt
Enhance
Plugins/SiriusXM/Bin/sxm.plso that the currently selected server is saved along with the existing channel cache data, and restored when the script is restarted. This will persist the server selection across reloads without creating new files or data structures—just add a key (such aslast_server) to the cached data structure used for channels. Be sure to save the server info when writing channel data to cache, and read it when loading the channel cache on restart.Requirements:
sxm.pl.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: What is the best way to remember which server we are currently using between reloads of sxm.pl
Assistant: The best way to persistently remember which server you are currently using between reloads of
sxm.plis to store the server selection in a persistent location that survives process restarts. Common approaches include:1. Configuration File
Store the server information in a configuration file (e.g.,
server_state.conf,last_server.txt, or in the main config file).Sample Perl logic:
2. Environment Variable (Not Persistent)
Setting an environment variable (e.g.,
$ENV{SIRIUSXM_SERVER}) will only keep the value for the current shell or process session. This is not persistent across reloads, so not suitable unless you use a wrapper script that always sets this variable on startup.3. Database/Key-Value Store
If the plugin already uses a database or a key-value store for other state, record the current server there.
4. Command-Line Argument (Not Persistent)
You could require specifying the server with each start, but this is manual and not automatic.
Recommendation:
For simple use cases, a dedicated small text file (
last_server.txt) is usually the easiest and most portable solution. It avoids race conditions, is simple to implement, works across platforms, and requires no dependencies.Let me know if you want a code snippet customized for your exact logic, or if your
sxm.plsetup already uses a config system that should be leveraged!User: we already are caching channel data and loading at restart, perhaps just save and load it there.
Assistant: That’s a great idea! If your
sxm.plscript already serializes and reloads channel data at startup/shutdown (using, for example, a cache file like a JSON, YAML, or Perl Storable), the cleanest solution is to add the current server to the same persistent data structure.Steps
Example
Suppose you currently have code like this for storing channel cache (in Perl pseudo-code):
Just expand this to include the server:
If using JSON or YAML, do the same—just add a key/value pair for the server.
Advantages
Conclusion:
Saving and restoring the current server information along with your existing channel cache data is the most cohesive and robust approach. Just add a field like
last_server(oractive_server) to your cached data structure.If you want a concrete code patch, just tell me the format you use for the cache (Storable, JSON, etc.) and I’ll provide a patch!
User: Just assign an agent to this task please
Assistant: To proceed and assign an agen...
This pull request was created from Copilot chat.