Best JavaScript code snippet using redwood
workflow.service.js
Source:workflow.service.js
1(function() {2 'use strict';3 angular4 .module('pteroWorkflowClient.services')5 .constant('TERMINAL_STATUSES', ['errored', 'failed', 'succeeded', 'canceled'])6 .factory('Workflow', WorkflowService);7 /* @ngInject */8 function WorkflowService($q, $log, _, moment, TERMINAL_STATUSES, Reports) {9 // PUBLIC ATTRIBUTES10 ////////////11 var workflow = {};12 var executions = [];13 // PUBLIC FUNCTIONS14 ////////////15 function get(workflowId) {16 var deferred = $q.defer();17 $q.all({18 skeleton: Reports.get({reportType: 'workflow-skeleton', workflow_id: workflowId}),19 // details: Reports.get({reportType: 'workflow-details', workflow_id: workflowId}),20 //outputs: Reports.get({reportType: 'workflow-outputs', workflow_id: workflowId}),21 executions: Reports.get({reportType: 'workflow-executions', workflow_id: workflowId})22 //,status: Reports.get({reportType: 'workflow-status', workflow_id: workflowId}),23 //submissionData: Reports.get({reportType: 'workflow-submission-data', workflow_id: workflowId})24 })25 .then(function(result) {26 workflow = parseResult(result);27 deferred.resolve(workflow);28 })29 .catch(function(error) {30 $log.error('Error fetching details for workflow.');31 deferred.reject('Error fetching details for workflow.');32 });33 return deferred.promise;34 }35 function getExecutions() {36 var deferred = $q.defer();37 $q.when(executions)38 .then(function(result) {39 deferred.resolve(result)40 });41 return deferred.promise;42 }43 // FACTORY MODULE44 ////////////45 var factory = {46 workflow: workflow,47 executions: executions,48 get: get,49 getExecutions: getExecutions50 };51 return factory;52 // PRIVATE FUNCTIONS53 //////////54 // Ptero::Proxy::Workflow->_concrete_workflow()55 function parseResult(result) {56 var wf = newWorkflow(result.skeleton);57 createExecutions(result.executions, wf);58 return wf;59 }60 // Ptero::Concrete::Workflow->new()61 function newWorkflow(sk) {62 var wf = {63 id: sk.id,64 rootTaskId: sk.rootTaskId,65 name: sk.name,66 type: 'workflow',67 status: sk.status,68 methodIndex: {},69 taskIndex: {},70 tasks: _.map(sk.tasks, newTask),71 executions: {}72 };73 // REGISTER WORKFLOW COMPONENTS (Ptero::Concrete::Workflow->register_components()74 // Ptero::Concrete::Workflow::Task->register_with_workflow()75 _.each(wf.tasks, function(task) {76 wf.taskIndex[task.id] = task;77 registerWithWorkflow(task);78 });79 function registerWithWorkflow(component) {80 _.each(component.tasks, registerTask);81 _.each(component.methods, registerMethod);82 function registerTask(task) {83 task.type = 'task';84 wf.taskIndex[task.id] = task;85 _.each(task.methods, function(method) {86 registerMethod(method);87 _.each(method.tasks, registerTask);88 });89 return true;90 }91 function registerMethod(method) {92 method.type = 'method';93 wf.methodIndex[method.id] = method;94 _.each(method.tasks, function(task) {95 registerTask(task);96 _.each(task.methods, registerMethod);97 });98 return true;99 }100 }101 return wf;102 }103 // Ptero::Concrete::Workflow::Task->new()104 function newTask(task, name) {105 //$log.debug('--- creating Task: ' + taskName);106 //$log.debug(task);107 // get each task's methods108 return {109 id: task.id,110 name: name,111 type: 'task',112 parallelBy: task.parallelBy,113 topologicalIndex: task.topologicalIndex,114 methods: getTaskMethods(task),115 executions: {}116 };117 function getTaskMethods(task) {118 var parseMethod = {119 'job': newMethod,120 'workflow': newDag,121 'workflow-block': newMethod,122 'workflow-converge': newMethod123 };124 return _.map(task.methods, function(method) {125 return parseMethod[method.service](method);126 });127 // Ptero::Concrete::Workflow::Method->new()128 function newMethod(method) {129 //$log.debug('----- parsing method: ' + method.name);130 //$log.debug(method);131 return {132 id: method.id,133 name: method.name,134 type: 'method',135 service: method.service,136 serviceUrl: method.serviceUrl ? method.serviceUrl : null, // only job methods have serviceUrls137 executions: {}138 };139 }140 // corresponds to Ptero::Concrete::Workflow::DAG->new()141 function newDag(dag) {142 //$log.debug('----- parsing dag: ' + dag.name);143 //$log.debug(dag);144 return {145 id: dag.id,146 name: dag.name,147 type: 'dag',148 service: dag.service,149 tasks: _.map(dag.parameters.tasks, newTask),150 executions: {}151 };152 }153 }154 }155 function createExecutions(exec, wf) { // corresponds to Ptero::Concrete::Workflow->create_executions()156 angular.copy([], executions);157 _.each(exec.executions, function (exec, name, execs) {158 var execution = newExecution(exec, name);159 // $log.debug('------ Execution.parentType: ' + execution.parentType);160 if(execution.parentId === wf.rootTaskId && execution.parentType === 'task') {161 // this is a root execution so drop it into this.executions162 wf.executions[execution.color] = execution;163 executions.push(execution);164 } else {165 // sub-task or method execution, find parent and assign166 var parent;167 if (execution.parentType === 'method') {168 parent = wf.methodIndex[execution.parentId];169 } else if (execution.parentType === 'task') {170 parent = wf.taskIndex[execution.parentId];171 } else {172 console.error('createExecutions() received execution with unknown parentType: ' + execution.parentType);173 return;174 }175 if(!_.isUndefined(parent)) {176 //$log.debug('found parent ' + parent.id + ' for execution ' + execution.id);177 //$log.debug(execution);178 parent.executions[execution.color] = execution;179 }180 executions.push(execution);181 }182 });183 }184 function newExecution(exec, color) { // corresponds to Ptero::Concrete::Workflow::Execution->new()185 return {186 id: exec.id,187 type: 'execution',188 parentId: getParentId(exec),189 parentType: getParentType(exec),190 timeStarted: getTimeStarted(exec),191 timeEnded: getTimeEnded(exec),192 duration: getDuration(exec),193 status: exec.status,194 statusHistory: exec.statusHistory,195 isTerminal: isTerminal(exec),196 isSuccess: isSuccess(exec),197 isAbnormal: isAbnormal(exec),198 isRunning: isRunning(exec),199 begins: exec.begins,200 color: exec.color,201 colors: exec.colors,202 parallelIndexes: getParallelIndexes(exec),203 parentColor: exec.parentColor,204 detailsUrl: exec.detailsUrl,205 childWorkflowUrls: _.has(exec, 'childWorkflowUrls') ? exec.childWorkflowUrls : [],206 details: _.has(exec, 'data') ? { data: exec.data, name: exec.name, inputs: exec.inputs } : {}207 };208 function getTimestamp(status, statusHistory) {209 var ts = _.find(statusHistory, { status: status });210 return ts != undefined ? ts.timestamp : false;211 }212 function getParentId(e) {213 if (_.has(e, 'taskId')) { return e.taskId }214 else if (_.has(e, 'methodId')) { return e.methodId }215 else { console.error('Could not set parentId for unknown execution type.'); return null; }216 }217 function getParentType(e) {218 if (_.has(e, 'taskId')) { return 'task' }219 else if (_.has(e, 'methodId')) { return 'method' }220 else { console.error('Could not set parentType for unknown execution type.'); return null; }221 }222 function isTerminal(e) {223 return _.contains(TERMINAL_STATUSES, e.status);224 }225 function isSuccess(e) {226 return e.status === 'succeeded';227 }228 function isAbnormal(e) {229 return isTerminal(e) && !isSuccess(e);230 }231 function isRunning(e) {232 return e.status === 'running';233 }234 function getTimeStarted(e) {235 if(getTimestamp('running', e.statusHistory)) { return getTimestamp('running', e.statusHistory); }236 else if(getTimestamp('errored', e.statusHistory)) { return getTimestamp('errored', e.statusHistory); }237 else { return getTimestamp('new', e.statusHistory); }238 }239 function getTimeEnded(e) {240 if(isTerminal(e)){241 return getTimestamp(e.status, e.statusHistory)242 } else {243 return new Date();244 }245 }246 function getDuration(e) {247 return moment.duration(moment(getTimeEnded(e)).diff(moment(getTimeStarted(e)))).asMilliseconds();248 }249 function getParallelIndexes(e) {250 return _.map(_.rest(e.colors), function(color, index) {251 return color - e.begins[index+1];252 });253 }254 }255 }...
executions.js
Source:executions.js
...47 var data = req.body;48 //delete data._id;49 data.project = req.cookies.project;50 data.user = req.cookies.username;51 CreateExecutions(app.getDB(),data,function(returnData){52 //exports.updateExecutionTotals(returnData._id,function(){53 res.contentType('json');54 res.json({55 success: true,56 executions: returnData57 });58 realtime.emitMessage("AddExecutions",data);59 //});60 });61};62exports.updateExecutionTotals = function(executionID,callback){63 var db = require('../common').getDB();64 db.collection('executiontestcases', function(err, collection) {65 collection.aggregate([{$match:{executionID : executionID,baseState:{$ne: true}}},{$group:{_id:null,total:{$sum:"$runtime"}}}],function(err,result){66 if(!result[0]) {67 if (callback){68 callback(err);69 }70 return;71 }72 var runtime = result[0].total;73 collection.aggregate([{$match:{executionID : executionID,baseState:{$ne: true}}},{$group:{_id:{result:"$result"},count:{$sum:1}}}],function(err,result){74 var failed = 0;75 var passed = 0;76 var total = 0;77 result.forEach(function(result){78 total = total + result.count;79 if(result._id.result == "Failed") failed = result.count;80 if(result._id.result == "Passed") passed = result.count;81 });82 var notRun = total - (failed + passed);83 db.collection('executions', function(err, collection) {84 collection.findAndModify({_id : executionID},{},{$set:{runtime:runtime,failed:failed,passed:passed,total:total,notRun:notRun}},{safe:true,new:true,upsert:true},function(err,data){85 if(data != null){86 realtime.emitMessage("UpdateExecutions",data);87 }88 if (callback){89 callback(err);90 }91 });92 });93 });94 });95 });96};97function CreateExecutions(db,data,callback){98 db.collection('executions', function(err, collection) {99 //data._id = db.bson_serializer.ObjectID(data._id);100 //collection.update({}, {$set:{uploadResultsALM:false}}, {multi:true});101 //collection.update({}, {$set:{almTestSetPath:""}}, {multi:true});102 var app = require('../common');103 app.logger.info('updated');104 collection.save(data, {safe:true},function(err,returnData){105 callback(returnData);106 });107 });108}109function UpdateExecutions(db,data,callback){110 db.collection('executions', function(err, collection) {111 collection.save(data,{safe:true},function(err){...
Using AI Code Generation
1const redwood = require('@project-redwood/redwood');2const { CreateExecutions } = require('@project-redwood/redwood');3async function run() {4 const result = await CreateExecutions({5 {6 },7 });8 console.log(result);9}10run();11const redwood = require('@project-redwood/redwood');12async function run() {13 const result = await redwood.CreateExecutions({14 {15 },16 });17 console.log(result);18}19run();
Using AI Code Generation
1var redwood = require('redwood');2var client = new redwood.Client();3var workflow = new redwood.Workflow();4var execution = new redwood.Execution();5var task = new redwood.Task();6var createExecutions = new redwood.CreateExecutions();7workflow.setName("workflow1");8workflow.setVersion("1.0");9task.setName("task1");10task.setVersion("1.0");11task.setType("SIMPLE");12execution.setWorkflow(workflow);13execution.setTask(task);14execution.setPriority(1);15execution.setWorkflowType("SIMPLE");16execution.setWorkflowVersion("1.0");17var executions = [];18executions.push(execution);19createExecutions.setExecutions(executions);20client.createExecutions(createExecutions, function(err, response) {21 if(err) {22 console.log(err);23 }24 else {25 console.log(response);26 }27});28var redwood = require('redwood');29var client = new redwood.Client();30var task = new redwood.Task();31var createTask = new redwood.CreateTask();32task.setName("task1");33task.setVersion("1.0");34task.setType("SIMPLE");35createTask.setTask(task);36client.createTask(createTask, function(err, response) {37 if(err) {38 console.log(err);39 }40 else {41 console.log(response);42 }43});44var redwood = require('redwood');45var client = new redwood.Client();46var workflow = new redwood.Workflow();47var createWorkflow = new redwood.CreateWorkflow();48workflow.setName("workflow1");49workflow.setVersion("1.0");50createWorkflow.setWorkflow(workflow);51client.createWorkflow(createWorkflow, function(err, response) {52 if(err) {53 console.log(err);54 }55 else {56 console.log(response);57 }58});
Using AI Code Generation
1var redwood = require('./redwoodAPI.js');2var fs = require('fs');3var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));4var redwood = new redwood(config);5var test = function () {6 var payload = {7 {8 {9 }10 }11 {12 {13 {
Using AI Code Generation
1var redwood = require('redwood');2var redwoodConfig = require('./redwood-config.json');3var redwoodClient = new redwood.Client(redwoodConfig);4var options = {5 "input": {6 },7 "taskToDomain": {8 }9};10redwoodClient.createExecution(options, function(err, result) {11 if (err) {12 console.log(err);13 return;14 }15 console.log(result);16});17var redwood = require('redwood');18var redwoodConfig = require('./redwood-config.json');19var redwoodClient = new redwood.Client(redwoodConfig);20var options = {21};22redwoodClient.getExecutionStatus(options, function(err, result) {23 if (err) {24 console.log(err);25 return;26 }27 console.log(result);28});29var redwood = require('redwood');30var redwoodConfig = require('./redwood-config.json');31var redwoodClient = new redwood.Client(redwoodConfig);32var options = {33};34redwoodClient.terminateExecution(options, function(err, result) {35 if (err) {36 console.log(err);37 return;38 }39 console.log(result);40});41var redwood = require('redwood');42var redwoodConfig = require('./redwood-config.json');43var redwoodClient = new redwood.Client(redwoodConfig);44var options = {45};46redwoodClient.getExecutionHistory(options, function(err, result) {47 if (err) {48 console.log(err);49 return;50 }51 console.log(result);52});
Using AI Code Generation
1var redwood = require('redwood');2var username = 'admin';3var password = 'admin';4var workflowName = 'HelloWorld';5var input = 'Hello World!';6var client = redwood.createClient(url, username, password);7client.createExecution(workflowName, input, function (err, execution) {8 if (err) {9 console.error(err);10 } else {11 console.log(execution);12 }13});14### redwood.createClient(url, username, password)15### client.getWorkflows(callback)16### client.getWorkflow(workflowName, callback)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!