private async Task <JobResult> CreateJobAsync(IRuleActionHandler actionHandler, EnrichedEvent enrichedEvent, RuleContext context, Instant now) { var actionName = typeNameRegistry.GetName(context.Rule.Action.GetType()); var expires = now.Plus(Constants.ExpirationTime); var job = new RuleJob { Id = DomainId.NewGuid(), ActionData = string.Empty, ActionName = actionName, AppId = enrichedEvent.AppId.Id, Created = now, EventName = enrichedEvent.Name, ExecutionPartition = enrichedEvent.Partition, Expires = expires, RuleId = context.RuleId }; try { var(description, data) = await actionHandler.CreateJobAsync(enrichedEvent, context.Rule.Action); var json = jsonSerializer.Serialize(data); job.ActionData = json; job.ActionName = actionName; job.Description = description; return(new JobResult { Job = job, EnrichedEvent = enrichedEvent }); } catch (Exception ex) { job.Description = "Failed to create job"; return(JobResult.Failed(ex, enrichedEvent, job)); } }
private async Task <(RuleJob, Exception?)> CreateJobAsync(Rule rule, DomainId ruleId, IRuleActionHandler actionHandler, Instant now, EnrichedEvent enrichedEvent) { var actionName = typeNameRegistry.GetName(rule.Action.GetType()); var expires = now.Plus(Constants.ExpirationTime); var job = new RuleJob { Id = DomainId.NewGuid(), ActionData = string.Empty, ActionName = actionName, AppId = enrichedEvent.AppId.Id, Created = now, EventName = enrichedEvent.Name, ExecutionPartition = enrichedEvent.Partition, Expires = expires, RuleId = ruleId }; try { var(description, data) = await actionHandler.CreateJobAsync(enrichedEvent, rule.Action); var json = jsonSerializer.Serialize(data); job.ActionData = json; job.ActionName = actionName; job.Description = description; return(job, null); } catch (Exception ex) { job.Description = "Failed to create job"; return(job, ex); } }