public async Task <IActionResult> StartPlatformJob() { try { string userId = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value; bool isRunning = this.jobsFactory.IsPlatformJobRunning(userId); PlatformJobsDTO job = null; if (!isRunning) { await this.jobsFactory.StartPlatform(userId, this.TradingPlatform); job = await jobRepo.GetLast(userId); job.IsRunning = true; } return(Ok(job)); } catch (Exception ex) { log.Log(ex); return(BadRequest()); } }
public async Task StartPlatformJob(CancellationTokenSource stoppingToken, string userId) { this.stoppingToken = stoppingToken; PlatformJobsDTO platformJob = await this.jobRepo.Insert(new PlatformJobsDTO() { StartTime = DateTime.UtcNow }, userId); this.PlatformLogService.Log(platformJob.ID, userId, "Starting Platform Job...", eventType.Info); while (!stoppingToken.IsCancellationRequested) { this.PlatformLogService.Log(platformJob.ID, userId, "Running Strategies...", eventType.Info); await this.RunStrategies(); await Task.Delay(60 * 10 * 1000, stoppingToken.Token); } }