public async Task MostRecentFirst()
        {
            IEntityManager      database    = TestSetup.CreateMemoryDatabase();
            DatabaseTaskService taskservice = new DatabaseTaskService(database);

            for (int i = 0; i < 31; ++i)
            {
                await taskservice.StoreTask(new WorkableTask()
                {
                    Id       = Guid.NewGuid(),
                    Started  = new DateTime(2020, 01, 1 + i),
                    Finished = new DateTime(2020, 01, i + 1, 1, 0, 0)
                });
            }

            Page <WorkableTask> tasks = await taskservice.ListTasks(new TaskFilter {
                Count = 10,
            });

            Assert.AreEqual(10, tasks.Result.Length);
            Assert.AreEqual(31, tasks.Result[0].Started.Day);
        }
Exemple #2
0
        public async Task ProfileLoopPerformance()
        {
            Mock <IScriptImportService> importservice = new Mock <IScriptImportService>();

            importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object);

            IEntityManager           database         = TestSetup.CreateMemoryDatabase();
            CacheService             cache            = new CacheService(new NullLogger <CacheService>());
            IScriptCompiler          compiler         = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, importservice.Object, null, null);
            WorkflowCompiler         workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler);
            WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, null, workflowcompiler);

            WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure {
                Name  = "JS Test",
                Nodes = new[] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "0"
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Iterator,
                        Parameters = new Dictionary <string, object> {
                            ["Collection"] = "[1,2,3,4,5]",
                            ["Item"]       = "number"
                        },
                    },
                    new NodeData {
                        Type       = NodeType.BinaryOperation,
                        Parameters = new Dictionary <string, object> {
                            ["Lhs"] = "$result",
                            ["Rhs"] = "$number",
                            ["Op"]  = BinaryOperation.Add
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$result"
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                    new IndexTransition {
                        OriginIndex = 1,
                        TargetIndex = 2,
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 3,
                        Type        = TransitionType.Loop,
                        Log         = "$\"Adding number {$number}\""
                    },
                    new IndexTransition {
                        OriginIndex = 3,
                        TargetIndex = 2
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 4
                    },
                }
            }), new Dictionary <string, object>(), true);

            await task.Task;

            Assert.AreEqual(TaskStatus.Success, task.Status);
            Assert.That(task.Log.Any(l => l.Contains("calls")));
            Assert.AreEqual(15, task.Result);
        }
Exemple #3
0
        public async Task ExecuteSubWorkflowWithParametersInLoop()
        {
            Mock <IScriptImportService> importservice = new Mock <IScriptImportService>();

            importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object);
            Mock <IArchiveService> archiveservice = new Mock <IArchiveService>();

            IEntityManager           database         = TestSetup.CreateMemoryDatabase();
            CacheService             cache            = new CacheService(new NullLogger <CacheService>());
            IScriptCompiler          compiler         = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, archiveservice.Object, importservice.Object, null, null);
            IWorkflowService         workflowservice  = new DatabaseWorkflowService(database, archiveservice.Object);
            WorkflowCompiler         workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, workflowservice, compiler);
            WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, workflowservice, workflowcompiler);

            await workflowservice.CreateWorkflow(new WorkflowStructure {
                Name  = "Submarine",
                Nodes = new [] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$value"
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                }
            });

            WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure {
                Name  = "Subcall Test",
                Nodes = new[] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "0",
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Iterator,
                        Parameters = new Dictionary <string, object> {
                            ["Item"]       = "value",
                            ["Collection"] = "[1,2,3,4,5]"
                        }
                    },
                    new NodeData {
                        Type       = NodeType.Workflow,
                        Parameters = new Dictionary <string, object> {
                            ["Name"]      = "Submarine",
                            ["Arguments"] = new Dictionary <string, object> {
                                ["value"] = "$value"
                            }
                        },
                        Variable = "subresult"
                    },
                    new NodeData {
                        Type       = NodeType.BinaryOperation,
                        Parameters = new Dictionary <string, object> {
                            ["Lhs"]       = "$result",
                            ["Operation"] = BinaryOperation.Add,
                            ["Rhs"]       = "$subresult"
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$result",
                        }
                    },
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                    new IndexTransition {
                        OriginIndex = 1,
                        TargetIndex = 2
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 3,
                        Type        = TransitionType.Loop
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 5
                    },
                    new IndexTransition {
                        OriginIndex = 3,
                        TargetIndex = 4
                    },
                    new IndexTransition {
                        OriginIndex = 4,
                        TargetIndex = 2
                    },
                }
            }), new Dictionary <string, object>(), false);

            await task.Task;

            Assert.AreEqual(TaskStatus.Success, task.Status);
            Assert.AreEqual(15, task.Result);
        }
Exemple #4
0
        public async Task SuspendAndContinueWithParameters()
        {
            IEntityManager           database         = TestSetup.CreateMemoryDatabase();
            CacheService             cache            = new CacheService(new NullLogger <CacheService>());
            IScriptCompiler          compiler         = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, null, null, null);
            WorkflowCompiler         workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler);
            WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, null, workflowcompiler);

            WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure {
                Name  = "Test",
                Nodes = new[] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Suspend,
                        Parameters = new Dictionary <string, object> {
                            ["Variable"] = "x"
                        }
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = 10
                        }
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = 5
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1,
                    },
                    new IndexTransition {
                        OriginIndex = 1,
                        TargetIndex = 2,
                        Condition   = "$x>=3"
                    },
                    new IndexTransition {
                        OriginIndex = 1,
                        TargetIndex = 3,
                    }
                }
            }), new Dictionary <string, object>(), false);

            await task.Task;

            Assert.AreEqual(TaskStatus.Suspended, task.Status);

            task = await executionservice.Continue(task.Id, new Dictionary <string, object> {
                ["x"] = 5
            });

            await task.Task;

            Assert.AreEqual(TaskStatus.Success, task.Status);
            Assert.AreEqual(10, task.Result);
        }
Exemple #5
0
        public async Task ProfileSubWorkflow()
        {
            Mock <IScriptImportService> importservice = new Mock <IScriptImportService>();

            importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object);
            Mock <IArchiveService> archiveservice = new Mock <IArchiveService>();

            IEntityManager           database         = TestSetup.CreateMemoryDatabase();
            CacheService             cache            = new CacheService(new NullLogger <CacheService>());
            IScriptCompiler          compiler         = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, archiveservice.Object, importservice.Object, null, null);
            IWorkflowService         workflowservice  = new DatabaseWorkflowService(database, archiveservice.Object);
            WorkflowCompiler         workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, workflowservice, compiler);
            WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, workflowservice, workflowcompiler);

            await workflowservice.CreateWorkflow(new WorkflowStructure {
                Name  = "Submarine",
                Nodes = new [] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Name       = "Subvalue",
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$job.id"
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                }
            });

            WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure {
                Name  = "Subcall Test",
                Nodes = new[] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Workflow,
                        Name       = "Call Submarine",
                        Parameters = new Dictionary <string, object> {
                            ["Name"]      = "Submarine",
                            ["Arguments"] = new Dictionary <string, object> {
                                ["job"] = new Dictionary <string, object> {
                                    ["id"] = 1.0
                                }
                            }
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1
                    },
                }
            }), new Dictionary <string, object>(), true);

            await task.Task;

            Assert.AreEqual(TaskStatus.Success, task.Status);
            Assert.That(task.Log.Any(l => l.Contains("calls")));
            Assert.AreEqual(1.0, task.Result);
        }
        public async Task SumConditionalLoop()
        {
            IEntityManager           database         = TestSetup.CreateMemoryDatabase();
            CacheService             cache            = new CacheService(new NullLogger <CacheService>());
            IScriptCompiler          compiler         = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, null, new Mock <IPythonService>().Object, null);
            WorkflowCompiler         workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler);
            WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, null, workflowcompiler);

            WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure {
                Name  = "Test",
                Nodes = new[] {
                    new NodeData {
                        Type = NodeType.Start
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = 0
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Iterator,
                        Parameters = new Dictionary <string, object> {
                            ["Collection"] = "[1,5,2,2,8,7,4]"
                        }
                    },
                    new NodeData {
                        Type       = NodeType.BinaryOperation,
                        Parameters = new Dictionary <string, object> {
                            ["lhs"]       = "$result",
                            ["rhs"]       = "$item",
                            ["operation"] = "Add"
                        },
                        Variable = "result"
                    },
                    new NodeData {
                        Type       = NodeType.Value,
                        Parameters = new Dictionary <string, object> {
                            ["Value"] = "$result"
                        }
                    }
                },
                Transitions = new[] {
                    new IndexTransition {
                        OriginIndex = 0,
                        TargetIndex = 1,
                    },
                    new IndexTransition {
                        OriginIndex = 1,
                        TargetIndex = 2,
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 3,
                        Type        = TransitionType.Loop,
                        Condition   = "$item&1==0"
                    },
                    new IndexTransition {
                        OriginIndex = 2,
                        TargetIndex = 4,
                    },
                    new IndexTransition {
                        OriginIndex = 3,
                        TargetIndex = 2
                    }
                }
            }), new Dictionary <string, object>(), false);

            await task.Task;

            Assert.AreEqual(Dto.TaskStatus.Success, task.Status);
            Assert.AreEqual(16, task.Result);
        }