converge: phase 2 — SSE relay client for realtime pull on push
- RepoConfig gains rcGiteaRepo :: Maybe Text for relay matching - Options gains optRelayUrl :: Maybe Text (--relay-url CLI, relay_url config) - connectRelay connects to converge-relay SSE endpoint, parses push events, triggers gitPull on matching repos (by gitea_repo + branch) - Exponential backoff reconnection (1s .. 60s) on disconnect/error - Skips pull if repo is mid-operation (merge/rebase/etc.) - Dependencies: http-client, http-client-tls, http-types, aeson, bytestring - SSE parser handles event:/data: fields, blank-line delimiters, CRLF endings - Updated SPEC.md, example config, and help text
This commit is contained in:
+18
-5
@@ -24,6 +24,8 @@ data CliArgs = CliArgs
|
||||
-- ^ Log file path.
|
||||
, cliSync :: !Bool
|
||||
-- ^ Run a single sync cycle and exit (useful for wake-from-sleep hooks).
|
||||
, cliRelayUrl :: !(Maybe Text)
|
||||
-- ^ URL of a converge-relay SSE endpoint (overrides config).
|
||||
}
|
||||
|
||||
cliParser :: Parser CliArgs
|
||||
@@ -97,6 +99,13 @@ cliParser =
|
||||
<> short 's'
|
||||
<> help "Run a single sync cycle (commit + pull + push) and exit"
|
||||
)
|
||||
<*> optional
|
||||
( strOption
|
||||
( long "relay-url"
|
||||
<> metavar "URL"
|
||||
<> help "URL of a converge-relay SSE endpoint for realtime push notifications"
|
||||
)
|
||||
)
|
||||
|
||||
parserInfo :: ParserInfo CliArgs
|
||||
parserInfo =
|
||||
@@ -114,7 +123,7 @@ main = do
|
||||
(options, configSource) <- case cliConfig cli of
|
||||
Just cfgPath -> do
|
||||
cfg <- loadConfig cfgPath
|
||||
let opts = applyOverrides mDebounceOverride (cliLogLevel cli) (cliLogFile cli) (configToOptions cfg)
|
||||
let opts = applyOverrides mDebounceOverride (cliLogLevel cli) (cliLogFile cli) (cliRelayUrl cli) (configToOptions cfg)
|
||||
pure (opts, Just cfgPath)
|
||||
Nothing -> do
|
||||
exists <- configFileExists
|
||||
@@ -122,7 +131,7 @@ main = do
|
||||
then do
|
||||
cfgPath <- defaultConfigPath
|
||||
cfg <- loadConfig cfgPath
|
||||
let opts = applyOverrides mDebounceOverride (cliLogLevel cli) (cliLogFile cli) (configToOptions cfg)
|
||||
let opts = applyOverrides mDebounceOverride (cliLogLevel cli) (cliLogFile cli) (cliRelayUrl cli) (configToOptions cfg)
|
||||
pure (opts, Just cfgPath)
|
||||
else
|
||||
pure
|
||||
@@ -130,6 +139,7 @@ main = do
|
||||
mDebounceOverride
|
||||
(cliLogLevel cli)
|
||||
(cliLogFile cli)
|
||||
(cliRelayUrl cli)
|
||||
defaultOptions
|
||||
{ optRepos =
|
||||
[ defaultRepoConfig
|
||||
@@ -168,13 +178,16 @@ main = do
|
||||
mapM_ (\r -> hPutStrLn stderr (" - " <> rcPath r)) repos
|
||||
runConverge options
|
||||
|
||||
-- | Apply CLI overrides (debounce, log level, log file) to Options.
|
||||
applyOverrides :: Maybe Int -> Maybe LogLevel -> Maybe FilePath -> Options -> Options
|
||||
applyOverrides mDebounce mLogLevel mLogFile opts =
|
||||
-- | Apply CLI overrides (debounce, log level, log file, relay url) to Options.
|
||||
applyOverrides :: Maybe Int -> Maybe LogLevel -> Maybe FilePath -> Maybe Text -> Options -> Options
|
||||
applyOverrides mDebounce mLogLevel mLogFile mRelayUrl opts =
|
||||
opts
|
||||
{ optDebounceMs = maybe (optDebounceMs opts) id mDebounce
|
||||
, optLogLevel = fromMaybe (optLogLevel opts) mLogLevel
|
||||
, optLogFile = case mLogFile of
|
||||
Just _ -> mLogFile -- CLI --log-file overrides config
|
||||
Nothing -> optLogFile opts
|
||||
, optRelayUrl = case mRelayUrl of
|
||||
Just _ -> mRelayUrl -- CLI --relay-url overrides config
|
||||
Nothing -> optRelayUrl opts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user