예제 #1
0
        public void CreateWorkflow2()
        {
            var dl  = WorkflowJob.MakeJob(() => WorkflowMethod("Download"));
            var co1 = WorkflowJob.MakeJob(() => FailingWorkflowMethod("Do something 1"), maxRetries: 1);
            var co2 = WorkflowJob.MakeJob(() => WorkflowMethod("Do something 2"));
            var co3 = WorkflowJob.MakeJob(() => WorkflowMethod("Do something 3"));
            var se1 = WorkflowJob.MakeJob(() => WorkflowMethod("Send email 1"));
            var se3 = WorkflowJob.MakeJob(() => WorkflowMethod("Send email 3"));
            var de  = WorkflowJob.MakeJob(() => WorkflowMethod("Delete email"));

            de.WaitFor(se1, co2, se3);
            co1.ContinueWith(se1);
            co3.ContinueWith(se3);
            var group = WorkflowJobGroup.RunInParallel(co1, co2, co3);

            dl.ContinueWithGroup(group);

            var wf = new Workflow(dl);

            GlobalConfiguration.Configuration.UseSqlServerStorage("db");

            var client = new BackgroundJobClient();

            client.CreateAndEnqueue(wf);
        }
예제 #2
0
        public void Run_CreateOrUpdateRecurringJob_ReturnsNotNullWithWorkflow_WhenExists(string schema)
        {
            var queryService = new QueryService(new SqlServerStorageOptions()
            {
                SchemaName = schema
            });

            UseConnection((conn) =>
            {
                var job1 = WorkflowJob.MakeJob(() => Run_CreateOrUpdateRecurringJob_ReturnsNotNullWithWorkflow_WhenExists(""), "dflt2", Guid.NewGuid(), 4, "new");
                var job2 = WorkflowJob.MakeJob(() => Run_CreateOrUpdateRecurringJob_ReturnsNotNullWithWorkflow_WhenExists("asd"), "dfldasdt2", Guid.NewGuid(), 2, "new2");
                job1.ContinueWith(job2);
                var sc = new Core.Common.ScheduledTask()
                {
                    Cron     = "0 0 0 0",
                    Workflow = new Workflow(job1),
                    Name     = "recurring_name",
                    OnlyIfLastFinishedOrFailed = true,
                    LastInvocation             = DateTime.Today,
                    NextInvocation             = DateTime.Today
                };
                var result = queryService.CreateOrUpdateRecurringJob(sc, conn);
                Assert.Equal(1, result);
                var recurring = conn.Query <ScheduleEntity>($"SELECT * FROM [{schema}].Schedule").FirstOrDefault();
                Assert.Equal(sc.Cron, recurring.Cron);
                Assert.Equal(sc.OnlyIfLastFinishedOrFailed, recurring.OnlyIfLastFinishedOrFailed);
                Assert.Equal(sc.LastInvocation, recurring.LastInvocation);
                Assert.Equal(sc.Name, recurring.Name);
                Assert.Equal(sc.NextInvocation, recurring.NextInvocation);
                Assert.Equal(JobHelper.ToJson(sc.Workflow), recurring.WorkflowInvocationData);
                Assert.Equal(JobHelper.ToJson(ScheduledJobInvocationData.FromScheduledJob(sc)), recurring.JobInvocationData);
            });
        }
예제 #3
0
        public void Workflow()
        {
            var rootJob = WorkflowJob.MakeJob(() => RecurringMethod("1 task", 1));

            rootJob.ContinueWith(WorkflowJob.MakeJob(() => RecurringMethod("2 task", 2)))
            .ContinueWithGroup(
                WorkflowJobGroup.RunInParallel(
                    WorkflowJob.MakeJob(() => RecurringMethod("3 task", 3)),
                    WorkflowJob.MakeJob(() => RecurringMethod("4 task", 4))
                    )).ContinueWith(
                WorkflowJob.MakeJob(() => RecurringMethod("5 task", 5)
                                    ));

            var wf = new Workflow(rootJob);

            wf.SaveWorkflow((t) => { t.QueueJob.JobId = (int)t.QueueJob.Job.Arguments[1]; Debug.WriteLine($"SAved: {t.QueueJob.JobId} - {t.QueueJob.Job.Arguments[0]}"); return((int)t.QueueJob.Job.Arguments[1]); });

            var jobs = wf.GetAllJobs().ToList();
        }
예제 #4
0
        public void CreateRecurringWorkflow()
        {
            var dl  = WorkflowJob.MakeJob(() => WorkflowMethod("Download"));
            var co1 = WorkflowJob.MakeJob(() => WorkflowMethod("Do something 1"));
            var co2 = WorkflowJob.MakeJob(() => WorkflowMethod("Do something 2"));
            var co3 = WorkflowJob.MakeJob(() => WorkflowMethod("Do something 3"));
            var se1 = WorkflowJob.MakeJob(() => WorkflowMethod("Send email 1"));
            var se3 = WorkflowJob.MakeJob(() => WorkflowMethod("Send email 3"));
            var de  = WorkflowJob.MakeJob(() => WorkflowMethod("Delete email"));

            de.WaitFor(se1, co2, se3);
            co1.ContinueWith(se1);
            co3.ContinueWith(se3);
            var group = WorkflowJobGroup.RunInParallel(co1, co2, co3);

            dl.ContinueWithGroup(group);

            var wf = new Workflow(dl);

            GlobalConfiguration.Configuration.UseSqlServerStorage("db");
            RecurringWorkflow.AddOrUpdate("test workflow", wf, Cron.MinuteInterval(1));
        }
예제 #5
0
        public void CreateWorkflow()
        {
            GlobalConfiguration.Configuration.UseSqlServerStorage("db");

            var contextId = Guid.NewGuid();

            var job1   = WorkflowJob.MakeJob(() => WorkflowMethod("1 task"), contextId: contextId);
            var job2   = WorkflowJob.MakeJob(() => WorkflowMethod("2 task"), contextId: contextId);
            var job31  = WorkflowJob.MakeJob(() => WorkflowMethod("3.1 task"), contextId: contextId);
            var job32  = WorkflowJob.MakeJob(() => WorkflowMethod("3.2 task"), contextId: contextId);
            var job321 = WorkflowJob.MakeJob(() => WorkflowMethod("3.2.1 task"), contextId: contextId);
            var group  = WorkflowJobGroup.RunInParallel(
                job31,
                job32
                );

            var job4 = WorkflowJob.MakeJob(() => WorkflowMethod("4 task"), contextId: contextId);
            var job5 = WorkflowJob.MakeJob(() => WorkflowMethod("5 task"), contextId: contextId);

            job1.ContinueWith(job2);
            job2.ContinueWithGroup(group);
            group.ContinueWith(job4);
            job4.ContinueWith(job5);
            job32.ContinueWith(job321);

            //rootJob.ContinueWith(WorkflowJob.MakeJob(() => RecurringMethod("2 task", 2))
            //    .ContinueWithGroup(
            //        WorkflowJob.MakeJob(() => RecurringMethod("3 task", 3)),
            //        WorkflowJob.MakeJob(() => RecurringMethod("4 task", 4))
            //    ).ContinueWith(WorkflowJob.MakeJob(() => RecurringMethod("5 task", 5))));

            var wf     = new Workflow(job1);
            var client = new BackgroundJobClient();

            client.CreateAndEnqueue(wf);
        }