/// <summary> /// Performs the core execution /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task that when complete will signal the completion of this work</returns> /// <inheritdoc /> public Task Process(CancellationToken cancellationToken) { return(EventHub.Get <ExcelReportComplete>().ForEachAsync(message => { // todo: fix var shouldUpload = false; // SettingsRepository.GetBool(UploadExcelToS3, true); if (!shouldUpload) { Log.Information("Skipping upload excel report to s3. Is the setting {UploadExcelToS3} set to true?", UploadExcelToS3); return; } // note: this looks for ~/.aws/credentials for a profile named default // see https://docs.aws.amazon.com/AmazonS3/latest/dev/walkthrough1.html#walkthrough1-add-users // todo: move this out to a decoupled component BasicAWSCredentials creds; try { var accessKey = ""; // SettingsRepository.Get("aws-access-key-id"); var secretKey = ""; // SettingsRepository.Get("aws-secret-key"); creds = new BasicAWSCredentials(accessKey, secretKey); } catch (Exception e) { Log.Error("Unable to create credentials for S3 client: {Message}", e.Message); return; } using (var client = new AmazonS3Client(creds, RegionEndpoint.USEast1)) using (var fs = File.OpenRead(message.ReportFile)) { var putReportRequest = new PutObjectRequest { // todo: this sould be a setting BucketName = "", // SettingsRepository.Get(ExcelBucketId), Key = message.ReportFile, InputStream = fs }; // todo: make a service Log.Information("Attempting to upload report to S3"); try { var putObjectResponse = client.PutObject(putReportRequest); if (putObjectResponse.HttpStatusCode == HttpStatusCode.OK) { Log.Information($"Upload of {message.ReportFile} was successful"); } else { throw new ApplicationException("Unknown error"); } } catch (Exception e) { Log.Error(e, "Unable to upload {ReportFile} to S3: {Message}", message.ReportFile, e.Message); } } }, cancellationToken)); }
/// <inheritdoc /> public Task Process(CancellationToken cancellationToken) { var messages = EventHub.Get <DummyMessage>(); var task = messages.Select(x => x.Amount).Sum().ToTask(cancellationToken); Thread.Sleep(1000); return(task); }
/// <summary> /// Performs any required setup like number crunching etc. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A Task, that when complete will signal the setup completion</returns> /// <inheritdoc /> public async Task Setup(CancellationToken cancellationToken) { var stackFrameBreakdownTask = EventHub.Get <StackFrameBreakdownMessage>() .FirstOrDefaultAsync().ToTask(cancellationToken); var uniqueStackTask = EventHub.Get <UniqueStacksMessage>().FirstOrDefaultAsync().ToTask(cancellationToken); await Task.WhenAll(stackFrameBreakdownTask, uniqueStackTask); StackFrameBreakdownMessage = stackFrameBreakdownTask.Result; UniqueStacksMessage = uniqueStackTask.Result; }
public async Task Get_All_Types_At_Or_Bellow_The_Requested() { // arrange var eventHub = new EventHub(); eventHub.Broadcast(new A()); eventHub.Broadcast(new B()); eventHub.Broadcast(new C()); eventHub.Shutdown(); // act var isGood = await eventHub.Get <B>().All(b => b is B); // assert isGood.Should().BeTrue(); }
public void Identify_Unique_Stacks() { // arrange var repo = new DumpThreadRepositoryBuilder() .WithThreads(new DumpThread[] { new DumpThread() { ManagedStackFramesInternal = { new DumpStackFrame() { DisplayString = "Foo()", ModuleName = "A" }, new DumpStackFrame() { DisplayString = "Bar()", ModuleName = "B" }, new DumpStackFrame() { DisplayString = "Baz()", ModuleName = "C" }, new DumpStackFrame() { DisplayString = "Faz()", ModuleName = "D" }, } }, new DumpThread() { ManagedStackFramesInternal = { new DumpStackFrame() { DisplayString = "Foo()", ModuleName = "A" }, new DumpStackFrame() { DisplayString = "Bar()", ModuleName = "B" }, new DumpStackFrame() { DisplayString = "Baz()", ModuleName = "C" }, new DumpStackFrame() { DisplayString = "Faz()", ModuleName = "D" }, } }, new DumpThread() { ManagedStackFramesInternal = { new DumpStackFrame() { DisplayString = "Foo()", ModuleName = "A" }, new DumpStackFrame() { DisplayString = "Bar()", ModuleName = "B" }, new DumpStackFrame() { DisplayString = "Baz()", ModuleName = "C" }, } }, }) .Build(); var eventHub = new EventHub(); var analyzer = new ThreadAnalyzer() { DumpThreadRepository = repo, EventHub = eventHub }; var stackObs = eventHub.Get <StackFrameBreakdownMessage>(); var uniqueObs = eventHub.Get <UniqueStacksMessage>(); // act analyzer.Setup(CancellationToken.None).Wait(); analyzer.Process(CancellationToken.None).Wait(); eventHub.Shutdown(); // assert analyzer.UniqueStackFrameResultsInternal.Should().HaveCount(2); analyzer.StackFrameResultsInternal.Should().HaveCount(4); stackObs.SingleAsync().Wait().Records.Should().HaveCount(4); uniqueObs.SingleAsync().Wait().UniqueStackFrameRollupRecords.Should().HaveCount(2); }