Skip to content

Commit

Permalink
Merge pull request #262 from skadefro/master
Browse files Browse the repository at this point in the history
close 1.4.35
  • Loading branch information
skadefro authored Jan 8, 2023
2 parents de46cd1 + 5e9e12b commit 4f51275
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 228 deletions.
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
FROM node:lts-alpine as builder

RUN npm install --omit=optional gulp typescript browserify tsify -g
# --omit=optional
RUN npm install gulp typescript browserify tsify -g

RUN mkdir /app
WORKDIR /app
COPY package*.json /app/
RUN npm install --omit=optional
RUN npm install
COPY . /app/
RUN gulp sass

RUN gulp
RUN tsc --build OpenFlow/tsconfig.json

FROM node:lts-alpine
ENV NODE_ENV=production
RUN apk add --no-cache bash
EXPOSE 3000
EXPOSE 5858
WORKDIR /data
COPY --from=builder /app/package*.json .
COPY --from=builder /app/dist/ .
# RUN npm install --omit=optional --omit=dev
# RUN npm install --omit=dev
# RUN npm install mongodb
RUN npm install --omit=dev --production

Expand Down
2 changes: 1 addition & 1 deletion OpenFlow/src/DBHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ export class DBHelper {
"$or": [
{ robotqueue: { "$exists": true, $nin: [null, "", "(empty)"] }, workflowid: { "$exists": true, $nin: [null, "", "(empty)"] } },
{ amqpqueue: { "$exists": true, $nin: [null, "", "(empty)"] } }]
}, collectionname: "mq", jwt: Crypt.rootToken()
}, top:1000, collectionname: "mq", jwt: Crypt.rootToken()
}, span);
}
public async GetPushableQueues(parent: Span): Promise<WorkitemQueue[]> {
Expand Down
20 changes: 11 additions & 9 deletions OpenFlow/src/DatabaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export class DatabaseConnection extends events.EventEmitter {
public ensureQueueMonitoring() {
if (Config.workitem_queue_monitoring_enabled) {
if (this.queuemonitoringhandle == null) {
this.queuemonitoringhandle = setInterval(this.queuemonitoring.bind(this), Config.workitem_queue_monitoring_interval);
// this.queuemonitoringhandle = setTimeout(this.queuemonitoring.bind(this), Config.workitem_queue_monitoring_interval);
// this.queuemonitoringhandle = setInterval(this.queuemonitoring.bind(this), Config.workitem_queue_monitoring_interval);
this.queuemonitoringhandle = setTimeout(this.queuemonitoring.bind(this), Config.workitem_queue_monitoring_interval);
// } else {
// Logger.instanse.warn("DatabaseConnection", "ensureQueueMonitoring", "queue monitoring restarted, clearing handle " + this.queuemonitoringhandle);
// try {
Expand All @@ -222,8 +222,8 @@ export class DatabaseConnection extends events.EventEmitter {
Logger.instanse.warn("queue monitoring stopeed, clearing enabled: " +
Config.workitem_queue_monitoring_enabled + " handle: " + this.queuemonitoringhandle, null);
try {
clearInterval(this.queuemonitoringhandle);
// clearTimeout(this.queuemonitoringhandle);
// clearInterval(this.queuemonitoringhandle);
clearTimeout(this.queuemonitoringhandle);
} catch (error) {
}
this.queuemonitoringhandle = null;
Expand All @@ -240,8 +240,10 @@ export class DatabaseConnection extends events.EventEmitter {
const jwt = Crypt.rootToken();
const collectionname = "workitems";
var queues = await Logger.DBHelper.GetPushableQueues(null);
for (var _wiq = 0; _wiq < queues.length; _wiq++) {
const wiq = queues[_wiq];
var test = queues.find(x => x._id == "63b6a9b41e86860136c2cc8b");
// wiq._id == "63b6a9b41e86860136c2cc8b"
for (let i = 0; i < queues.length; i++) {
const wiq = queues[i];
const count = await Logger.DBHelper.GetPendingWorkitemsCount(wiq._id, null);
if (count < 1) continue;
const query = { "wiqid": wiq._id, state: "new", "_type": "workitem", "nextrun": { "$lte": new Date(new Date().toISOString()) } };
Expand All @@ -257,7 +259,7 @@ export class DatabaseConnection extends events.EventEmitter {
if (!NoderedUtil.IsNullEmpty(wiq.amqpqueue)) {
queueid = wiq.amqpqueue.toLowerCase();
}
if (NoderedUtil.IsNullEmpty(queueid)) return;
if (NoderedUtil.IsNullEmpty(queueid)) { continue;}
for (var _cid = 0; _cid < WebSocketServer._clients.length; _cid++) {
const client = WebSocketServer._clients[_cid];
if (NoderedUtil.IsNullUndefinded(client.user)) continue;
Expand Down Expand Up @@ -296,8 +298,8 @@ export class DatabaseConnection extends events.EventEmitter {
Logger.instanse.error(error, null);
}
finally {
// this.queuemonitoringhandle = null;
// this.ensureQueueMonitoring();
this.queuemonitoringhandle = null;
this.ensureQueueMonitoring();
}
}
async GlobalWatchCallback(collectionname: string, next: any) {
Expand Down
7 changes: 7 additions & 0 deletions OpenFlow/src/Messages/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4565,6 +4565,7 @@ export class Message {
if (typeof wi.payload !== 'object') wi.payload = { "value": wi.payload };
wi.priority = msg.priority;
wi.nextrun = msg.nextrun;
if (!NoderedUtil.IsNullEmpty(msg.wipriority)) wi.priority = msg.wipriority;
if (NoderedUtil.IsNullEmpty(wi.priority)) wi.priority = 2;
wi.failed_wiq = msg.failed_wiq;
wi.failed_wiqid = msg.failed_wiqid;
Expand Down Expand Up @@ -4760,6 +4761,8 @@ export class Message {
wi.payload = item.payload ? item.payload : {};
if (typeof wi.payload !== 'object') wi.payload = { "value": wi.payload };
wi.priority = item.priority;
if (!NoderedUtil.IsNullEmpty(msg.wipriority)) wi.priority = msg.wipriority;
if (NoderedUtil.IsNullEmpty(wi.priority)) wi.priority = 2;
wi.nextrun = item.nextrun;
wi.state = "new"
wi.retries = 0;
Expand Down Expand Up @@ -4920,6 +4923,7 @@ export class Message {
if (NoderedUtil.IsNullEmpty(msg.errortype)) wi.errortype = "application";
}
if (!NoderedUtil.IsNullUndefinded(msg.errorsource)) wi.errorsource = msg.errorsource;
if (!NoderedUtil.IsNullEmpty(msg.wipriority)) wi.priority = msg.wipriority;
if (NoderedUtil.IsNullEmpty(wi.priority)) wi.priority = 2;

var oldstate = wi.state;
Expand All @@ -4944,6 +4948,9 @@ export class Message {
wi.username = null;
wi.nextrun = new Date(new Date().toISOString());
wi.nextrun.setSeconds(wi.nextrun.getSeconds() + wiq.retrydelay);
if(!NoderedUtil.IsNullEmpty(msg.nextrun)) {
wi.nextrun = new Date(msg.nextrun);
}
} else {
wi.state = "failed";
}
Expand Down
3 changes: 2 additions & 1 deletion OpenFlow/src/dockerdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class dockerdriver implements i_nodered_driver {
await docker.listContainers();
return true;
} catch (error) {
Logger.instanse.error(error, null);
Logger.instanse.info("Docker not detected: " + error.message, null);
// Logger.instanse.error(error, null);
}
return false;
}
Expand Down
37 changes: 21 additions & 16 deletions OpenFlow/src/public/CommonControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class textarea implements ng.IDirective {
}
}

export class ngtype implements ng.IDirective {
export class ngtype { // implements ng.IDirective
restrict = 'A';
require = '?ngModel';
constructor(public $location: ng.ILocationService, public $timeout: ng.ITimeoutService) {
Expand All @@ -295,24 +295,29 @@ export class ngtype implements ng.IDirective {
var mytype = "";
scope.$watch((newValue) => {
if (ngModelCtrl.$viewValue === null || ngModelCtrl.$viewValue === undefined) { return; }
if(mytype != "") return;;
if (typeof ngModelCtrl.$modelValue === 'number') {
mytype = "number";
element.attr("type", "number");
} else if (typeof ngModelCtrl.$modelValue === 'boolean') {
mytype = "boolean";
element.attr("type", "checkbox");
} else {
mytype = "text";
element.attr("type", "text");
}

});

var toModelb = function (value) {
if (mytype == "text") {
return value;
} else if (mytype == "boolean") {
if (String(value).toLowerCase() == "true") { value = true; return true; }
{ value = false; return false; }
if (mytype == "boolean") {
if (String(value).toLowerCase() == "true") { value = true; }
else { value = false; }
} else if (mytype == "number") {
if (value === "" || value === null || value === undefined) return value;
return parseInt(value);
if(!NoderedUtil.IsNullEmpty(value)) {
if(value.toString().indexOf(".")>=0) { value = parseFloat(value); }
else { value = parseInt(value); }
}
}
return value;
}
Expand All @@ -329,14 +334,14 @@ export class ngtype implements ng.IDirective {
element.attr("type", "text");
}
}
if (mytype == "text") {
return value;
} else if (mytype == "boolean") {
if (String(value).toLowerCase() == "true") { value = true; return true; }
{ value = false; return false; }
if (mytype == "boolean") {
if (String(value).toLowerCase() == "true") { value = true; }
else { value = false; }
} else if (mytype == "number") {
if (value === "" || value === null || value === undefined) return value;
return parseInt(value);
if(NoderedUtil.IsNullEmpty(value)) {
if(value.toString().indexOf(".")>=0) { value = parseFloat(value); }
else { value = parseInt(value); }
}
}
return value;
}
Expand Down Expand Up @@ -368,7 +373,7 @@ async function getString(locale: any, lib: string, key: string): Promise<any> {
});
}
const global_translate_notfound: string[] = [];
export class translate implements ng.IDirective {
export class translate { // implements ng.IDirective
require = '?ngModel';
replace = true;

Expand Down
40 changes: 38 additions & 2 deletions OpenFlow/src/public/Controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3976,6 +3976,21 @@ export class EntityCtrl extends entityCtrl<Base> {
}
});
}
cached = {}
getstep(key, obj) {
if(this.gettype(obj) == "number")
{
if (obj.toString().indexOf(".") > -1) {
var decimals = obj.toString().split(".")[1].length;
this.cached[key] = 1 / Math.pow(10, decimals);
return this.cached[key];
} else {
if (this.cached[key]) return this.cached[key];
}
}
this.cached[key] = 1;
return 1;
}
gettype(obj) {
return typeof obj;
}
Expand Down Expand Up @@ -6723,7 +6738,7 @@ export class WorkitemsCtrl extends entitiesCtrl<Base> {
this.basequery = { _type: "workitem" };
this.collection = "workitems";
this.searchfields = ["name", "state", "wiq"];
this.baseprojection = { name: 1, state: 1, wiq: 1, retries: 1, lastrun: 1, nextrun: 1 };
this.baseprojection = { name: 1, state: 1, wiq: 1, retries: 1, lastrun: 1, nextrun: 1, priority: 1 };
this.postloadData = this.processData;
if (this.userdata.data.WorkitemsCtrl) {
this.basequery = this.userdata.data.WorkitemsCtrl.basequery;
Expand Down Expand Up @@ -6851,6 +6866,7 @@ export class WorkitemCtrl extends entityCtrl<Workitem> {
this.model.retries = 0;
this.model.state = "new";
this.model.payload = {};
this.model.priority = 2;
if (this.userdata.data && this.userdata.data.WorkitemsCtrl) this.model.wiq = this.userdata.data.WorkitemsCtrl.queue;
if (!this.$scope.$$phase) { this.$scope.$apply(); }
}
Expand Down Expand Up @@ -6881,6 +6897,7 @@ export class WorkitemCtrl extends entityCtrl<Workitem> {
q.name = model.name;
q.wiq = model.wiq;
q.payload = model.payload;
q.wipriority = model.priority;
_msg.command = 'addworkitem';
_msg.data = JSON.stringify(q);
const result: AddWorkitemMessage = await WebSocketClient.instance.Send<AddWorkitemMessage>(_msg, 1);
Expand All @@ -6891,6 +6908,7 @@ export class WorkitemCtrl extends entityCtrl<Workitem> {
q.name = model.name;
q.state = model.state;
q.payload = model.payload;
q.wipriority = model.priority;
_msg.command = 'updateworkitem';
_msg.data = JSON.stringify(q);
const result: UpdateWorkitemMessage = await WebSocketClient.instance.Send<UpdateWorkitemMessage>(_msg, 1);
Expand Down Expand Up @@ -6930,7 +6948,7 @@ export class WorkitemQueuesCtrl extends entitiesCtrl<Base> {
this.basequery = { _type: "workitemqueue" };
this.collection = "mq";
this.searchfields = ["name"];
this.baseprojection = { name: 1, maxretries: 1, projectid: 1, workflowid: 1, robotqueue: 1, amqpqueue: 1 };
this.baseprojection = { name: 1, maxretries: 1, projectid: 1, workflowid: 1, robotqueue: 1, amqpqueue: 1, _createdby:1 };

this.postloadData = this.processData;
if (this.userdata.data.WorkitemQueuesCtrl) {
Expand Down Expand Up @@ -7021,6 +7039,7 @@ export class WorkitemQueueCtrl extends entityCtrl<WorkitemQueue> {
public users: Base[] = [];
public amqpqueues: Base[] = [];
public workitemqueues: Base[] = [];
public stats: string = "calculating...";
constructor(
public $rootScope: ng.IRootScopeService,
public $scope: ng.IScope,
Expand Down Expand Up @@ -7086,6 +7105,23 @@ export class WorkitemQueueCtrl extends entityCtrl<WorkitemQueue> {
if (NoderedUtil.IsNullEmpty(this.model.failed_wiqid)) this.model.failed_wiqid = "";
await this.loadselects();
if (!this.$scope.$$phase) { this.$scope.$apply(); }
var total = await NoderedUtil.Count({ collectionname: "workitems", query: { "wiqid": this.id } });
// this.stats = total + " items";
// if (!this.$scope.$$phase) { this.$scope.$apply(); }
if(total > 0) {
var newitems = await NoderedUtil.Count({ collectionname: "workitems", query: { "wiqid": this.id, "state": "new" } });
var successfulitems = await NoderedUtil.Count({ collectionname: "workitems", query: { "wiqid": this.id, "state": "successful" } });
var faileditems = await NoderedUtil.Count({ collectionname: "workitems", query: { "wiqid": this.id, "state": "failed" } });
var processingitems = await NoderedUtil.Count({ collectionname: "workitems", query: { "wiqid": this.id, "state": "processing" } });
this.stats = "";
if(newitems > 0) this.stats += "New: " + newitems;
if(successfulitems > 0) this.stats += " Successful: " + successfulitems;
if(faileditems > 0) this.stats += " Failed: " + faileditems;
if(processingitems > 0) this.stats += " Processing: " + processingitems;
} else {
this.stats = "No items";
}
if (!this.$scope.$$phase) { this.$scope.$apply(); }
}

async submit(): Promise<void> {
Expand Down
11 changes: 9 additions & 2 deletions OpenFlow/src/public/Entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,16 @@ <h1 class="pagetitle"><span translate lib="web">detailsfor</span> {{ctrl.model.n
</div>
<div ng-repeat="key in ctrl.keys" class="form-group" ng-show="!ctrl.isobject(ctrl.model[key]) && key != 'name'">
<label>{{ key }}</label>
<input type="{{ctrl.gettype(ctrl.model[key]) == 'boolean' ? 'checkbox' : 'text'}}" ng-model="ctrl.model[key]"
ng-type
<!-- no-model does not work for boolens if type has not been set before parsing ng-type -->

<input ng-model="ctrl.model[key]" ng-if="ctrl.gettype(ctrl.model[key]) != 'boolean'"
ng-model="ctrl.model[key]"
ng-type step="{{ctrl.getstep(key, ctrl.model[key])}}"
ng-class="{'form-control': ctrl.gettype(ctrl.model[key]) != 'boolean', 'secret': ctrl.model._encrypt.indexOf(key) > -1}" />
<input ng-model="ctrl.model[key]" ng-if="ctrl.gettype(ctrl.model[key]) == 'boolean'"
type="checkbox" ng-model="ctrl.model[key]"
ng-type step="{{ctrl.getstep(key, ctrl.model[key])}}"
ng-class="{'form-control': ctrl.gettype(ctrl.model[key]) != 'boolean', 'secret': ctrl.model._encrypt.indexOf(key) > -1}" />
</div>
<div ng-repeat="key in ctrl.keys" class="form-group" ng-show="ctrl.isobject(ctrl.model[key])">
<label>{{ key }}</label>
Expand Down
6 changes: 6 additions & 0 deletions OpenFlow/src/public/Workitem.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ <h1 class="pagetitle" translate lib="web">{{ctrl.model.name}}</h1>
<input type="number" ng-model="ctrl.model.retries" class="input-md" ng-disabled="true" />
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label" translate lib="web">priority</label>
<div class="col-sm-6">
<input type="number" ng-model="ctrl.model.priority" class="input-md" step=1 min=0 max=99 />
</div>
</div>
<div class="form-group" ng-show="ctrl.model.errormessage && ctrl.model.errormessage != ''">
<label for="newpassword" class="col-sm-2 control-label" translate lib="web">errormessage</label>
<div class="col-sm-4">
Expand Down
7 changes: 7 additions & 0 deletions OpenFlow/src/public/WorkitemQueue.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ <h1 class="pagetitle" translate lib="web">{{ctrl.model.name}}</h1>
<input ng-model="ctrl.model.name" class="form-control input-md" ng-disabled="ctrl.loading==true" />
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label" translate lib="web">stats</label>
<div class="col-sm-4">
<div>{{ctrl.stats}}</div>
</div>
</div>

<div class="form-group">
<label for="state" class="col-sm-2 control-label" translate lib="web">project</label>
<div class="col-sm-4">
Expand Down
2 changes: 2 additions & 0 deletions OpenFlow/src/public/WorkitemQueues.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h1>{{ctrl.queue}} <span translate lib="web">workitemqueues</span></h1>
<th ng-click="ctrl.ToggleOrder('name')"><strong translate lib="web">name</strong></th>
<th ng-click="ctrl.ToggleOrder('maxretries')"><strong translate lib="web">maxretries</strong></th>
<th ng-click="ctrl.ToggleOrder('projectid')"><strong translate lib="web">projectid</strong></th>
<th ng-click="ctrl.ToggleOrder('_createdby')" class="w-150"><strong translate lib="web">createdby</strong></th>
<th class="text-right"></th>
</tr>
</thead>
Expand All @@ -35,6 +36,7 @@ <h1>{{ctrl.queue}} <span translate lib="web">workitemqueues</span></h1>
{{model.projectid}}
</a>
</td>
<td class="text-truncate">{{model._createdby}}</td>
<td>
<div class="w-200 text-right">
<a class="btn" ng-href="#/WorkitemQueue/{{model._id}}" title="Edit Workitem queue">
Expand Down
Loading

0 comments on commit 4f51275

Please sign in to comment.