public JobStatus PollForStatus(string jobId, TimeSpan retryInterval) { var result = (JobStatus)JobSvc.GetStatus(User.UserName, User.Password, jobId); while (result != JobStatus.Completed && result != JobStatus.Failed) { Thread.Sleep(retryInterval); result = (JobStatus)JobSvc.GetStatus(User.UserName, User.Password, jobId); } return(result); }
/// <summary> /// Consumers can make orders /// </summary> public async Task DeleteTemporaryOrders() { try { int orderTimeOutMinutes = 15; string subjectPrefix = string.Format("Birdy order timeout ({0}min)", orderTimeOutMinutes); JobSvc jobSvc = new JobSvc(this.Ctx); DateTimeOffset now = DateTimeOffset.Now; DateTimeOffset deleteBefore = now.AddMinutes(-orderTimeOutMinutes); string message = string.Format("Check for inprogress orders created before {0:HH}h{0:mm}({0:ss})", deleteBefore); TrackTrace(message); int batchSize = 20, maxBatchNum = 100; for (int batchNum = 1; maxBatchNum <= 0 || batchNum <= maxBatchNum; batchNum++) { StringBuilder sbLog = new StringBuilder(); List <Order> orders = this.Ctx.Order.Include("Party").Include("OrderLines.ResourcePlannings") .Include("Appointments") .Where(o => o.IsActive && o.CreatedAt < deleteBefore && (o.OrderStatus & OrderStatus.InProgress) == OrderStatus.InProgress) .OrderBy(o => o.CreatedAt).Skip(batchSize * (batchNum - 1)).Take(batchSize).ToList(); if (orders == null || orders.Count == 0) { TrackTrace("No orders to inactivate!"); return; } TrackTrace(string.Format("{0} orders in progress older then {1} minutes: these will be placed on inactive (batch:{2})!", orders.Count, orderTimeOutMinutes, batchNum)); foreach (Order order in orders) { sbLog.AppendFormat(" Order {0:dd/MM/yy HHhmm} {1}", order.Date, order.Party != null ? order.Party.Name : "?").AppendLine(); if (order.OrderLines != null) { foreach (OrderLine orderLine in order.OrderLines) { if (orderLine.ResourcePlannings != null) { this.Ctx.ResourcePlanning.RemoveRange(orderLine.ResourcePlannings); /* * foreach (ResourcePlanning planning in orderLine.ResourcePlannings.ToList()) * { * planning.IsActive = false; * planning.IsDeleted = true; * * this.Ctx.ResourcePlanning.Remove(planning); * } */ } sbLog.AppendFormat(" {0}", orderLine.Description).AppendLine(); } } if (order.Appointments != null) { this.Ctx.Appointment.RemoveRange(order.Appointments); /* * foreach (Appointment app in order.Appointments) * { * app.IsActive = false; * app.IsDeleted = true; * } */ } order.IsActive = false; order.IsDeleted = true; order.OrderStatus = order.OrderStatus & ~OrderStatus.InProgress; order.OrderStatus = order.OrderStatus | OrderStatus.TimedOut; await jobSvc.QueueJob(JobType.SendOrderDebugInfo, new SendOrderDebugInfoRequest() { OrderId = order.Id, SubjectPrefix = subjectPrefix }); this.Ctx.SaveChanges(); } TrackTrace(sbLog.ToString()); } } catch (Exception ex) { this.Log.TrackException(ex); } }
public async Task <OrderActionResponse> ExecuteAction(OrderActionRequest request) { try { this.TrackTrace("OrderActionSvc.ExecuteAction(...) triggered", request); if (request == null || string.IsNullOrWhiteSpace(request.Action)) { return(new OrderActionResponse(OrderActionResponseStatus.ActionNotDefined)); } if (string.IsNullOrWhiteSpace(request.OrderId)) { return(new OrderActionResponse(OrderActionResponseStatus.OrderIdNotDefined)); } Order order = this.Ctx.Order.FirstOrDefault(o => o.Id == request.OrderId); BirdyMessagingSvc msgSvc = new BirdyMessagingSvc(this.Ctx); JobSvc jobSvc = new JobSvc(); switch (request.Action.Trim()) { case "confirmAndWaitForBankTransfer": order.OrderStatus = OrderStatus.Confirmed; order.PaymentStatus = (short)PaymentStatus.WaitingForPayment; this.Ctx.SaveChanges(); CreatePrivatePartyAndLinkToOrderIfNeeded(order); await msgSvc.ExecuteMessage(BirdyTemplateCode.C_ConfirmReservation, null, OpenBizObjectType.Order, request.OrderId); await jobSvc.QueueJob(JobType.SendOrderDebugInfo, new SendOrderDebugInfoRequest() { OrderId = order.Id, SubjectPrefix = "Birdy order action 'confirmAndWaitForBankTransfer'" }); this.TrackTrace("OrderActionSvc.ExecuteAction() successfully executed!", request); return(GetBankTransferStructuredMessage(order)); case "confirm": order.OrderStatus = OrderStatus.Confirmed; this.Ctx.SaveChanges(); CreatePrivatePartyAndLinkToOrderIfNeeded(order); await msgSvc.ExecuteMessage(BirdyTemplateCode.C_ConfirmReservation, null, OpenBizObjectType.Order, request.OrderId); await jobSvc.QueueJob(JobType.SendOrderDebugInfo, new SendOrderDebugInfoRequest() { OrderId = order.Id, SubjectPrefix = "Birdy order action 'confirm'" }); this.TrackTrace("OrderActionSvc.ExecuteAction() successfully executed!", request); break; case "getAdvanceMessage": return(GetBankTransferStructuredMessage(order)); default: this.TrackError(string.Format("Action '{0}' not recognised!", request.Action), request); break; } return(new OrderActionResponse(OrderActionResponseStatus.Ok)); } catch (Exception ex) { this.Log.TrackException(ex); return(new OrderActionResponse(OrderActionResponseStatus.ExceptionOccurred)); } }