Skip to content

Commit

Permalink
fix(Solution): Minor fixes and improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Charles d'Avernas <[email protected]>
  • Loading branch information
cdavernas committed Sep 10, 2024
1 parent f2ace89 commit 6d9bc18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ namespace Synapse.Runner.Services.Executors;
/// <param name="context">The current <see cref="ITaskExecutionContext"/></param>
/// <param name="schemaHandlerProvider">The service used to provide <see cref="ISchemaHandler"/> implementations</param>
/// <param name="serializer">The service used to serialize/deserialize objects to/from JSON</param>
public class ContainerProcessExecutor(IServiceProvider serviceProvider, ILogger<ContainerProcessExecutor> logger, ITaskExecutionContextFactory executionContextFactory, ITaskExecutorFactory executorFactory, IContainerPlatform containers, ITaskExecutionContext<RunTaskDefinition> context, ISchemaHandlerProvider schemaHandlerProvider, IJsonSerializer serializer)
/// <param name="options">The service used to access the current <see cref="RunnerOptions"/></param>
public class ContainerProcessExecutor(IServiceProvider serviceProvider, ILogger<ContainerProcessExecutor> logger, ITaskExecutionContextFactory executionContextFactory, ITaskExecutorFactory executorFactory,
IContainerPlatform containers, ITaskExecutionContext<RunTaskDefinition> context, ISchemaHandlerProvider schemaHandlerProvider, IJsonSerializer serializer, IOptions<RunnerOptions> options)
: TaskExecutor<RunTaskDefinition>(serviceProvider, logger, executionContextFactory, executorFactory, context, schemaHandlerProvider, serializer)
{

Expand All @@ -38,6 +40,11 @@ public class ContainerProcessExecutor(IServiceProvider serviceProvider, ILogger<
/// </summary>
protected ContainerProcessDefinition ProcessDefinition => this.Task.Definition.Run.Container!;

/// <summary>
/// Gets the current <see cref="RunnerOptions"/>
/// </summary>
protected RunnerOptions Options { get; } = options.Value;

/// <summary>
/// Gets the <see cref="IContainer"/> to run
/// </summary>
Expand All @@ -57,6 +64,7 @@ protected override async Task DoExecuteAsync(CancellationToken cancellationToken
await this.Container!.StartAsync(cancellationToken).ConfigureAwait(false);
await this.Container.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
var standardOutput = (this.Container.StandardOutput == null ? null : await this.Container.StandardOutput.ReadToEndAsync(cancellationToken).ConfigureAwait(false))?.Trim();
if (this.Options.Containers.Platform == ContainerPlatform.Docker) standardOutput = standardOutput?[8..];
var standardError = (this.Container.StandardError == null ? null : await this.Container.StandardError.ReadToEndAsync(cancellationToken).ConfigureAwait(false))?.Trim();
var result = standardOutput; //todo: do something with return data encoding (ex: plain-text, json);
await this.SetResultAsync(result, this.Task.Definition.Then, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ protected virtual async Task WaitForReadyAsync(CancellationToken cancellationTok
/// <inheritdoc/>
public virtual async Task WaitForExitAsync(CancellationToken cancellationToken = default)
{
var response = this.Kubernetes.CoreV1.ListNamespacedPodWithHttpMessagesAsync(this.Pod.Namespace(), fieldSelector: $"metadata.name={Pod.Name()}", cancellationToken: cancellationToken);
var response = this.Kubernetes.CoreV1.ListNamespacedPodWithHttpMessagesAsync(this.Pod.Namespace(), fieldSelector: $"metadata.name={Pod.Name()}", watch: true, cancellationToken: cancellationToken);
await foreach (var (_, item) in response.WatchAsync<V1Pod, V1PodList>(cancellationToken: cancellationToken).ConfigureAwait(false))
{
if (item.Status.Phase != "Succeeded" || item.Status.Phase != "Failed") continue;
if (item.Status.Phase != "Succeeded" && item.Status.Phase != "Failed") continue;
var containerStatus = item.Status.ContainerStatuses.FirstOrDefault();
this._exitCode = containerStatus?.State.Terminated?.ExitCode ?? -1;
break;
Expand Down

0 comments on commit 6d9bc18

Please sign in to comment.