Adds waiting for debug-mode start message
This commit is contained in:
parent
d6f7e225be
commit
fa1b560a91
|
@ -1,11 +1,13 @@
|
|||
using Core;
|
||||
using KubernetesWorkflow;
|
||||
using KubernetesWorkflow.Types;
|
||||
using Utils;
|
||||
|
||||
namespace CodexDiscordBotPlugin
|
||||
{
|
||||
public class CodexDiscordBotPlugin : IProjectPlugin, IHasLogPrefix, IHasMetadata
|
||||
{
|
||||
private const string ExpectedStartupMessage = "Debug option is set. Discord connection disabled!";
|
||||
private readonly IPluginTools tools;
|
||||
|
||||
public CodexDiscordBotPlugin(IPluginTools tools)
|
||||
|
@ -46,7 +48,9 @@ namespace CodexDiscordBotPlugin
|
|||
var startupConfig = new StartupConfig();
|
||||
startupConfig.NameOverride = config.Name;
|
||||
startupConfig.Add(config);
|
||||
return workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig).WaitForOnline();
|
||||
var pod = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig).WaitForOnline();
|
||||
WaitForStartupMessage(workflow, pod);
|
||||
return pod;
|
||||
}
|
||||
|
||||
private RunningPod StartRewarderContainer(IStartupWorkflow workflow, RewarderBotStartupConfig config)
|
||||
|
@ -55,5 +59,44 @@ namespace CodexDiscordBotPlugin
|
|||
startupConfig.Add(config);
|
||||
return workflow.Start(1, new RewarderBotContainerRecipe(), startupConfig).WaitForOnline();
|
||||
}
|
||||
|
||||
private void WaitForStartupMessage(IStartupWorkflow workflow, RunningPod pod)
|
||||
{
|
||||
var finder = new LogLineFinder(ExpectedStartupMessage, workflow);
|
||||
Time.WaitUntil(() =>
|
||||
{
|
||||
finder.FindLine(pod);
|
||||
return finder.Found;
|
||||
}, nameof(WaitForStartupMessage));
|
||||
}
|
||||
|
||||
public class LogLineFinder : LogHandler
|
||||
{
|
||||
private readonly string message;
|
||||
private readonly IStartupWorkflow workflow;
|
||||
|
||||
public LogLineFinder(string message, IStartupWorkflow workflow)
|
||||
{
|
||||
this.message = message;
|
||||
this.workflow = workflow;
|
||||
}
|
||||
|
||||
public void FindLine(RunningPod pod)
|
||||
{
|
||||
Found = false;
|
||||
foreach (var c in pod.Containers)
|
||||
{
|
||||
workflow.DownloadContainerLog(c, this);
|
||||
if (Found) return;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Found { get; private set; }
|
||||
|
||||
protected override void ProcessLine(string line)
|
||||
{
|
||||
if (!Found && line.Contains(message)) Found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue