Esempio n. 1
0
 public async Task MessageAsync(int jobId, string taskKey, [FromBody] ClusrunOutput output, CancellationToken token)
 {
     try
     {
         this.logger.Information("TaskMessage {0}, {1}, order {2}, eof {3}", jobId, taskKey, output.Order, output.Eof);
         await this.monitor.PutOutput(jobId, taskKey, output, token);
     }
     catch (Exception ex)
     {
         this.logger.Error(ex, "Error occurred, TaskMessage {0}, order {1}, eof {2}", taskKey, output.Order, output.Eof);
     }
 }
Esempio n. 2
0
            public async T.Task PutOutput(ClusrunOutput output, CancellationToken token)
            {
                await this.sem.WaitAsync(token);

                try
                {
                    if (output.Order == leftKey)
                    {
                        StringBuilder builder = new StringBuilder();

                        var i = output;

                        while (!i.Eof)
                        {
                            builder.Append(i.Content);


                            leftKey++;
                            if (!this.cache.TryRemove(leftKey, out ClusrunOutput tmp))
                            {
                                break;
                            }
                            else
                            {
                                i = tmp;
                            }
                        }

                        await this.processor(builder.ToString(), i.Eof, token);

                        if (i != null && i.Eof)
                        {
                            return;
                        }
                    }
                    else
                    {
                        this.cache.TryAdd(output.Order, output);
                        this.rightKey = Math.Max(this.rightKey, output.Order);
                    }
                }
                finally
                {
                    this.sem.Release();
                }
            }