public void With_Workflow_Job() { IAutomatedJob _getAuthToken = InlineJob.GetDefault((ctx) => { //call actual api and get Auth token var token = Guid.NewGuid().ToString(); //store the token in to Context store ctx.SetValue(token, "token-key"); //Console.WriteLine(token); return(new JobResult(JobStatus.Completed)); }); IAutomatedJob _download = InlineJob.GetDefault((ctx) => { //get Auth token from Context store var token = ctx.GetValue <string>("token-key"); //Console.WriteLine(token); // download the data using Auth token Task.Delay(200).Wait(); return(new JobResult(JobStatus.Completed)); }); //build integraion workflow - sequential by default - parallel also be possible IAutomatedJob _integraion = Builder.BuildWorkflow(InlineJob.GetJobId()) .WithOption(WhenFailure.StopOrExitJob, ShareContext.previous) .AddJob(_getAuthToken) .ThenAdd(_download) .NothingElse().Create(); //get notofication manager, from service repo var manager = ServiceRepo.Instance.GetServiceOf <INotificationManager <JobId> >(); //setup Message hooks var hanlder = new AggregateHandler(); manager.RegisterHook(_download.Id, MessageType.Info, hanlder); manager.RegisterHook(_getAuthToken.Id, MessageType.Info, hanlder); var result = _integraion.Doable(); //run the integration job Console.WriteLine(result.Status.ToString()); //Completed //wait for handler to aggregate the message hooks, since push is ASync Task.Delay(500).Wait(); //print the messages recieved hanlder.MessagesRecieved.ToList().ForEach(m => { Console.WriteLine(m.Item2.ToString()); }); }
public void With_Standalone_Job() { //setup Download job IAutomatedJob _download = InlineJob.GetDefault((ctx) => { //push ctx.PushReportToHookAsync(ctx.ParentJobId, new MessageHook("Download Started", "Info", MessageType.Info)); // download the data Task.Delay(200).Wait(); //push ctx.PushReportToHookAsync(ctx.ParentJobId, new MessageHook("Download Completed", "Info", MessageType.Info)); return(new JobResult(JobStatus.Completed)); }); //get notofication manager, from service repo var manager = ServiceRepo.Instance.GetServiceOf <INotificationManager <JobId> >(); //setup Message hooks var hanlder = new AggregateHandler(); manager.RegisterHook(_download.Id, MessageType.Info, hanlder); var result = _download.Doable(); //execute the job Console.WriteLine(result.Status.ToString()); //Completed //wait for handler to aggregate the message hooks, since push is ASync Task.Delay(500).Wait(); //print the messages recieved hanlder.MessagesRecieved.ToList().ForEach(m => { Console.WriteLine(m.Item2.ToString()); }); }