Example #1
0
 /// <summary>
 /// Apply an action on the rows
 /// </summary>
 /// <param name="observed">observed operation</param>
 /// <returns>resulting operation</returns>
 public static EtlResult Start(this IObservableOperation observed)
 {
     var op = new StartOperation();
     observed.Subscribe(op);
     op.Trigger();
     return op.Result;
 }
Example #2
0
 /// <summary>
 /// Start the operation in a thread. Start method calls are bubbled up through the pipeline
 /// </summary>
 public static EtlResult StartInThread(this IObservableOperation observed)
 {
     var op = new StartOperation();
     observed.Subscribe(op);            
     
     op.Result.Thread = new Thread(new ThreadStart(op.Trigger));
     op.Result.Thread.Start();
     
     return op.Result;
 }
Example #3
0
        public static async Task <IActionResult> RequestProcess(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = Routes.BaseProcess)] HttpRequest req,
            [Queue(QueueName, Connection = QueueConnectionName)] CloudQueue encryptionRequestsQueue)
        {
            var command = new StartOperation(Guid.NewGuid());

            var jsonMessage = System.Text.Json.JsonSerializer.Serialize(command);
            await encryptionRequestsQueue.AddMessageAsync(new CloudQueueMessage(jsonMessage));

            return(new AcceptedObjectResult(Routes.BuildProcessDetails(command.RequestId.ToString()), command));
        }
Example #4
0
        public void Start(StartOperation command)
        {
            Id     = command.RequestId;
            Status = ProcessStatus.Started;

            _logger.LogInformation($"starting new process {Id} ...");

            var runnerId = new EntityId(nameof(LongRunningProcessRunner), command.RequestId.ToString());

            _context.SignalEntity <ILongRunningProcessRunner>(runnerId, r => r.RunAsync(command));
        }
Example #5
0
        private void RunPlayerTest(string clipTitle, Func <TestContext, Task> testImpl)
        {
            AsyncContext.Run(async() =>
            {
                _logger.Info($"Begin: {NUnit.Framework.TestContext.CurrentContext.Test.FullName}");

                using (var cts = new CancellationTokenSource())
                {
                    using (var service = new PlayerService())
                    {
                        try
                        {
                            var context = new TestContext
                            {
                                Service   = service,
                                ClipTitle = clipTitle,
                                Token     = cts.Token,

                                // Requested seek position may differ from
                                // seek position issued to player. Difference can be 10s+
                                // Encrypted streams (Widevine in particular) may have LONG license
                                // installation times (10s+).
                                // DRM content has larger timeout
                                Timeout = TSPlayerServiceTestCaseSource.IsEncrypted(clipTitle)
                                    ? TimeSpan.FromSeconds(40)
                                    : TimeSpan.FromSeconds(20)
                            };
                            var prepareOperation = new PrepareOperation();
                            prepareOperation.Prepare(context);
                            await prepareOperation.Execute(context);

                            var startOperation = new StartOperation();
                            startOperation.Prepare(context);
                            await startOperation.Execute(context);

                            await testImpl(context);
                        }
                        catch (Exception e)
                        {
                            _logger.Error($"Error: {NUnit.Framework.TestContext.CurrentContext.Test.FullName} {e.Message} {e.StackTrace}");
                            throw;
                        }

                        // Test completed. Cancel token to kill any test's sub activities.
                        // Do so before PlayerService gets destroyed (in case those activities access it)
                        cts.Cancel();
                    }
                }

                _logger.Info($"End: {NUnit.Framework.TestContext.CurrentContext.Test.FullName}");
            });
        }
        public async Task RunAsync(StartOperation command)
        {
            var rand  = new Random(DateTime.UtcNow.Millisecond);
            var delay = TimeSpan.FromSeconds(rand.Next(60));

            _logger.LogInformation($"starting long running process {command.RequestId} for {delay} ...");

            await Task.Delay(delay);

            var orchestratorId = new EntityId(nameof(LongRunningProcessOrchestrator), command.RequestId.ToString());

            _context.SignalEntity <ILongRunningProcessOrchestrator>(orchestratorId, r => r.OnCompleted());
        }
Example #7
0
        public void Playback_StartFromThe90thSecond_PreparesAndStarts(string clipTitle)
        {
            RunPlayerTest(clipTitle, async context =>
            {
                context.SeekTime  = TimeSpan.FromSeconds(90);
                var seekOperation = new SeekOperation();
                seekOperation.Prepare(context);
                var seek = seekOperation.Execute(context);

                var startOperation = new StartOperation();
                startOperation.Prepare(context);
                await startOperation.Execute(context);

                await seek;
            }, false);
        }
Example #8
0
        public async Task Handle(StartOperation message)
        {
            var command = JsonConvert.DeserializeObject(message.CommandData, Type.GetType(message.CommandType));

            var op = await _dbContext.Operations.FindAsync(message.OperationId).ConfigureAwait(false);

            if (op == null)
            {
                MarkAsComplete();
                return;
            }

            op.Name = command.GetType().Name;

            if (command is IMachineCommand machineCommand)
            {
                var machine = await _dbContext.Machines.FindAsync(machineCommand.MachineId).ConfigureAwait(false);

                if (machine == null)
                {
                    if (command is IOptionalMachineCommand)
                    {
                        await Handle(new OperationCompletedEvent { OperationId = message.OperationId });
                    }
                    else
                    {
                        await Handle(new OperationFailedEvent()
                        {
                            OperationId = message.OperationId, ErrorMessage = "Machine not found"
                        });
                    }
                    return;
                }

                await _bus.Advanced.Routing.Send($"haipa.agent.{machine.AgentName}", command).ConfigureAwait(false);

                await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                return;
            }

            await _bus.Advanced.Topics.Publish("agent.all", command).ConfigureAwait(false);
        }
Example #9
0
 /// <summary>
 /// Notifies that an operation (or group of operations) is about to start
 /// </summary>
 protected virtual void OnStartOperation()
 {
     StartOperation?.Invoke();
 }
Example #10
0
 public void Start()
 {
     StartCallCount++;
     StartOperation?.Invoke();
 }