Fifth Attempt, Timeout |
Imagine that there is a lot of work to be done by Data Conveyer. This may take some time.
In the meantime we don't want to wait for too long. What can we do?
... and not a moment longer!
Data Conveyer supports cancellation. So, while at work, it will obediently react to a cancellation request.
using Mavidian.DataConveyer; using Mavidian.DataConveyer.Orchestrators; var cfg = new OrchestratorConfig() { InputDataKind = KindOfTextData.Delimited, InputFileNames = "input.csv", HeadersInFirstInputRow = true, OutputDataKind = KindOfTextData.Keyword, OutputFileNames = "output.kw" }; Task<ProcessResult> tsk; ProcessResult rslt; using (var orchtr = OrchestratorCreator.GetEtlOrchestrator(cfg)) { tsk = orchtr.ExecuteAsync(); Thread.Sleep(60000); //one minute //Instead of canceling the process after a period of time (depicted here), // it is better to use the TimeLimit configuration setting! orchtr.CancelExecution(); rslt = tsk.Result; } if (rslt.CompletionStatus == CompletionStatus.Canceled) { Console.WriteLine("Conversion process was canceled after one minute!"); } else if (rslt.CompletionStatus == CompletionStatus.IntakeDepleted) { Console.WriteLine($"Successfully converted {rslt.RowsWritten} records!"); }
The above example will work, but it is not ideal. Data Conveyer not only supports cancellation, but a timeout as well. So, instead of canceling after a given period of time, it is better to configure the TimeLimit setting. This way, we won't waste time waiting in case Data Conveyer process completes before the timeout expiration.
using Mavidian.DataConveyer; using Mavidian.DataConveyer.Orchestrators; var cfg = new OrchestratorConfig() { TimeLimit = TimeSpan.FromMinutes(1), InputDataKind = KindOfTextData.Delimited, InputFileName = "input.csv", HeadersInFirstInputRow = true, OutputDataKind = KindOfTextData.Keyword, OutputFileName = "output.kw" }; ProcessResult rslt; using (var orchtr = OrchestratorCreator.GetEtlOrchestrator(cfg)) { rslt = orchtr.ExecuteAsync().Result; } if (rslt.CompletionStatus == CompletionStatus.TimedOut) { Console.WriteLine("Conversion process timed out after one minute!"); } else if (rslt.CompletionStatus == CompletionStatus.IntakeDepleted) { Console.WriteLine($"Successfully converted {rslt.RowsWritten} records!"); }