Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: connector restart when uncaught error happens during run #214

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public override async Task Run(CancellationToken token)
}
_logger.LogError(innerEx, "An error occurred during task execution");
}
throw;
}
}
}
Expand Down
17 changes: 8 additions & 9 deletions Cognite.Simulator.Utils/SimulationRunnerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public async Task Run(CancellationToken token)
continue;
}

PublishConnectorStatus(ConnectorStatus.RUNNING_SIMULATION, token);
PublishConnectorStatus(ConnectorStatus.RUNNING_SIMULATION);

await InitSimulationRun(
runItem,
Expand Down Expand Up @@ -251,7 +251,7 @@ await InitSimulationRun(
if (!skipped)
{
_logger.LogDebug("Simulation run finished for run {Id}", runId);
PublishConnectorStatus(ConnectorStatus.IDLE, token);
PublishConnectorStatus(ConnectorStatus.IDLE);
ModelLibrary.WipeTemporaryModelFiles();
}
}
Expand Down Expand Up @@ -288,12 +288,12 @@ await InitSimulationRun(
if (simEv.Run.Status == SimulationRunStatus.running)
{
_logger.LogError("Simulation run {Id} could not finish properly. This could be due to a connector being unexpectedly stopped during the run", runId);
throw new ConnectorException("Simulation entered unrecoverable state failed");
throw new ConnectorException("Simulation entered unrecoverable state and failed");
}
return (model, calcConfig);
}

async void PublishConnectorStatus(ConnectorStatus status, CancellationToken token)
async void PublishConnectorStatus(ConnectorStatus status)
{
try
{
Expand All @@ -307,8 +307,7 @@ async void PublishConnectorStatus(ConnectorStatus status, CancellationToken toke
{
SimulatorExternalIds = new List<string>() { simulator.Name },
}
},
token).ConfigureAwait(false);
}).ConfigureAwait(false);
var integration = integrationRes.Items.FirstOrDefault(i => i.ExternalId == _connectorConfig.GetConnectorName());
if (integration == null)
{
Expand All @@ -327,12 +326,12 @@ await _cdfSimulators.UpdateSimulatorIntegrationAsync(
new SimulatorIntegrationUpdateItem(simulatorIntegrationId.Value) {
Update = simulatorIntegrationUpdate
}
},
token
}
).ConfigureAwait(false);
}
catch (ResponseException e)
catch (Exception e)
{
// This method should not throw exceptions as it is called in finally block
_logger.LogWarning("Failed to update simulator integration status: {Message}", e.Message);
}
}
Expand Down
Loading