示例#1
0
        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());
            });
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TJobInput"></typeparam>
        /// <typeparam name="TJobOutput"></typeparam>
        /// <param name="function"></param>
        /// <returns></returns>
        public PipelineBuilder <TIn, TOut> Register <TJobInput, TJobOutput>(Func <TJobInput, TJobOutput> function)
        {
            if (function == null)
            {
                throw new NullReferenceException("Inline function definition.");
            }

            var inlineJob = new InlineJob <TJobInput, TJobOutput>(function);

            return(Register(inlineJob));

            ;
        }
示例#3
0
        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());
            });
        }
        public void RetryJob()
        {
            IAutomatedJob _processFile = InlineJob.GetDefault((ctx) =>
            {
                //to simulate the retry when job failed
                throw new Exception("making the job failed");

                return(new JobResult(JobStatus.Completed));
            });

            //make the job as retry, when error/exception is anticipated
            var retry = _processFile.ConvertToRetry(3, TimeSpan.FromMilliseconds(500));

            ErrorHandle.Logger = NullLogger.Instance; //disable the default console logging

            var rResult = retry.Doable();             // run retry job

            Console.WriteLine(rResult.Status);        //CompletedWithError
            foreach (var r in retry.RetryResults)
            {
                Console.WriteLine(r.Error.Message); //print retry error/excpetion message
            }
        }
        public void WorkflowJob()
        {
            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();

            var result = _integraion.Doable();           //run the integration job

            Console.WriteLine(result.Status.ToString()); //Completed
        }