Skip to content

Commit 358a822

Browse files
authored
Merge pull request openiap#200 from skadefro/master
Close 1.4.4
2 parents 6a1fc09 + 251a27e commit 358a822

10 files changed

Lines changed: 149 additions & 14 deletions

File tree

OpenFlow/src/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class Config {
5959
Config.auto_hourly_housekeeping = Config.parseBoolean(Config.getEnv("auto_hourly_housekeeping", "false"));
6060
Config.housekeeping_update_usage_hourly = Config.parseBoolean(Config.getEnv("housekeeping_update_usage_hourly", "false"));
6161
Config.housekeeping_update_usersize_hourly = Config.parseBoolean(Config.getEnv("housekeeping_update_usersize_hourly", "true"));
62+
Config.housekeeping_skip_collections = Config.getEnv("housekeeping_skip_collections", "");
6263
Config.workitem_queue_monitoring_enabled = Config.parseBoolean(Config.getEnv("workitem_queue_monitoring_enabled", "true"));
6364
Config.workitem_queue_monitoring_interval = parseInt(Config.getEnv("workitem_queue_monitoring_interval", (30 * 1000).toString())); // 30 sec
6465

@@ -237,6 +238,7 @@ export class Config {
237238
public static auto_hourly_housekeeping: boolean = Config.parseBoolean(Config.getEnv("auto_hourly_housekeeping", "true"));
238239
public static housekeeping_update_usage_hourly: boolean = Config.parseBoolean(Config.getEnv("housekeeping_update_usage_hourly", "false"));
239240
public static housekeeping_update_usersize_hourly: boolean = Config.parseBoolean(Config.getEnv("housekeeping_update_usersize_hourly", "true"));
241+
public static housekeeping_skip_collections: string = Config.getEnv("housekeeping_skip_collections", "");
240242
public static workitem_queue_monitoring_enabled: boolean = Config.parseBoolean(Config.getEnv("workitem_queue_monitoring_enabled", "true"));
241243
public static workitem_queue_monitoring_interval: number = parseInt(Config.getEnv("workitem_queue_monitoring_interval", (30 * 1000).toString())); // 30 sec
242244

OpenFlow/src/DatabaseConnection.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,15 @@ export class DatabaseConnection extends events.EventEmitter {
260260
}
261261
if (!NoderedUtil.IsNullEmpty(wiq.robotqueue) && !NoderedUtil.IsNullEmpty(wiq.workflowid)) {
262262
Logger.instanse.verbose("[workitems] Send invoke message to robot queue " + wiq.workflowid);
263-
await amqpwrapper.Instance().send(null, wiq.robotqueue, payload, 5000, null, null, 2);
263+
let expiration = (Config.amqp_requeue_time / 2, 10) | 0;
264+
if (expiration < 500) expiration = 500;
265+
await amqpwrapper.Instance().send(null, wiq.robotqueue, payload, expiration, null, null, 2);
264266
}
265267
if (!NoderedUtil.IsNullEmpty(wiq.amqpqueue)) {
266268
Logger.instanse.verbose("[workitems] Send invoke message to amqp queue " + wiq.amqpqueue);
267-
await amqpwrapper.Instance().send(null, wiq.amqpqueue, payload, 5000, null, null, 2);
269+
let expiration = (Config.amqp_requeue_time / 2, 10) | 0;
270+
if (expiration < 500) expiration = 500;
271+
await amqpwrapper.Instance().send(null, wiq.amqpqueue, payload, expiration, null, null, 2);
268272
}
269273
}
270274
}

OpenFlow/src/Messages/Message.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class Message {
138138
await this.GetNoderedInstance(span);
139139
break;
140140
case "housekeeping":
141-
await this.Housekeeping(false, false, false, span);
141+
await this.Housekeeping(span);
142142
break;
143143
case "updateworkitemqueue":
144144
await this.UpdateWorkitemQueue(span);
@@ -656,10 +656,7 @@ export class Message {
656656
if (Config.enable_openflow_amqp) {
657657
cli.Send(await QueueClient.SendForProcessing(this, this.priority));
658658
} else {
659-
// await this.Housekeeping(false, false, false, span);
660-
Message.lastHouseKeeping = null;
661-
var msg = JSON.parse(this.data);
662-
await this.Housekeeping(msg.skipnodered, msg.skipcalculatesize, msg.skipupdateusersize, span);
659+
await this.Housekeeping(span);
663660
cli.Send(this);
664661
}
665662
break;
@@ -3559,7 +3556,33 @@ export class Message {
35593556
if (diffminutes < 60) return false;
35603557
return true;
35613558
}
3562-
public async Housekeeping(skipNodered: boolean, skipCalculateSize: boolean, skipUpdateUserSize: boolean, parent: Span): Promise<void> {
3559+
private async Housekeeping(parent: Span): Promise<void> {
3560+
this.Reply();
3561+
const span: Span = Logger.otel.startSubSpan("message.GetNoderedInstance", parent);
3562+
let msg: any;
3563+
try {
3564+
msg = JSON.parse(this.data);
3565+
Message.lastHouseKeeping = null;
3566+
if (NoderedUtil.IsNullEmpty(msg.skipnodered)) msg.skipnodered = false;
3567+
if (NoderedUtil.IsNullEmpty(msg.skipcalculatesize)) msg.skipcalculatesize = false;
3568+
if (NoderedUtil.IsNullEmpty(msg.skipupdateusersize)) msg.skipupdateusersize = false;
3569+
await this._Housekeeping(msg.skipnodered, msg.skipcalculatesize, msg.skipupdateusersize, span);
3570+
} catch (error) {
3571+
span?.recordException(error);
3572+
this.data = "";
3573+
await handleError(null, error);
3574+
if (msg !== null && msg !== undefined) msg.error = error.message ? error.message : error;
3575+
}
3576+
try {
3577+
this.data = JSON.stringify(msg);
3578+
} catch (error) {
3579+
span?.recordException(error);
3580+
this.data = "";
3581+
await handleError(null, error);
3582+
}
3583+
Logger.otel.endSpan(span);
3584+
}
3585+
public async _Housekeeping(skipNodered: boolean, skipCalculateSize: boolean, skipUpdateUserSize: boolean, parent: Span): Promise<void> {
35633586
if (Message.lastHouseKeeping == null) {
35643587
Message.lastHouseKeeping = new Date();
35653588
Message.lastHouseKeeping.setDate(Message.lastHouseKeeping.getDate() - 1);
@@ -3764,8 +3787,15 @@ export class Message {
37643787
collections = collections.filter(x => x.name.indexOf("system.") === -1);
37653788
let totalusage = 0;
37663789
let index = 0;
3790+
let skip_collections = [];
3791+
if (!NoderedUtil.IsNullEmpty(Config.housekeeping_skip_collections)) skip_collections = Config.housekeeping_skip_collections.split(",")
37673792
for (let col of collections) {
37683793
if (col.name == "fs.chunks") continue;
3794+
if (skip_collections.indexOf(col.name) > -1) {
3795+
Logger.instanse.debug("[housekeeping][" + col.name + "] skipped due to housekeeping_skip_collections setting");
3796+
continue;
3797+
}
3798+
37693799
index++;
37703800
let aggregates: any = [
37713801
{

OpenFlow/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function doHouseKeeping() {
5959
var msg2 = new Message(); msg2.jwt = Crypt.rootToken();
6060
var h = dt.getHours();
6161
var skipUpdateUsage: boolean = !(dt.getHours() == 1 || dt.getHours() == 13);
62-
msg2.Housekeeping(false, skipUpdateUsage, skipUpdateUsage, null).catch((error) => Logger.instanse.error(error));
62+
msg2._Housekeeping(false, skipUpdateUsage, skipUpdateUsage, null).catch((error) => Logger.instanse.error(error));
6363

6464
// var dt = new Date(new Date().toISOString());
6565
// var msg = new Message(); msg.jwt = Crypt.rootToken();

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.4.3",
3+
"version": "1.4.4",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

OpenFlowNodeRED/src/nodered/nodes/api.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,8 +1796,67 @@
17961796
</script>
17971797

17981798

1799+
<script type="text/x-red" data-template-name="api drop collection">
1800+
<div class="form-row">
1801+
<label><i class="fa fa-list"></i> Collection name</label>
1802+
<input type="hidden" id="node-input-collectionametype">
1803+
<input style="width:70%" type="text" id="node-input-collectioname">
1804+
</div>
1805+
<div class="form-row">
1806+
<label><i class="fa fa-tag"></i> Name</label>
1807+
<input type="text" id="node-input-name" placeholder="Name">
1808+
</div>
1809+
</script>
1810+
<script type="text/x-red" data-help-name="api drop collection">
1811+
<p>drop collection in the database <br>
1812+
</p>
1813+
</script>
1814+
<script type="text/javascript">
1815+
// https://fontawesome.com/v4.7/icon/list
1816+
RED.nodes.registerType('api drop collection', {
1817+
category: 'api',
1818+
color: "#E9967A",
1819+
paletteLabel: 'drop collection',
1820+
icon: "font-awesome/fa-list",
1821+
defaults: {
1822+
name: { value: "" },
1823+
collectioname: { value: "collectionname", validate: validate("collectionametype"), required: true },
1824+
collectionametype: { value: "msg", required: true },
1825+
},
1826+
inputs: 1,
1827+
outputs: 1,
1828+
label: function () {
1829+
return this.name || "drop collection";
1830+
},
1831+
labelStyle: function () {
1832+
return this.name ? "node_label_italic" : "";
1833+
},
1834+
oneditprepare: function () {
1835+
if (this.collectionametype === null) $("#node-input-collectionametype").val('msg');
1836+
if (this.collectionametype === 'val') $("#node-input-collectionametype").val('str');
1837+
$("#node-input-collectioname").typedInput({
1838+
default: 'msg',
1839+
typeField: $("#node-input-collectionametype"),
1840+
types: ['msg', 'str']
1841+
});
1842+
}
1843+
});
1844+
</script>
1845+
17991846

18001847
<script type="text/x-red" data-template-name="api housekeeping">
1848+
<div class="form-row">
1849+
<label><i class="fa fa-tag"></i> Skip Nodered</label>
1850+
<input type="checkbox" id="node-input-skipnodered" style="width: auto;">
1851+
</div>
1852+
<div class="form-row">
1853+
<label><i class="fa fa-tag"></i> Skip Calculate Size</label>
1854+
<input type="checkbox" id="node-input-skipcalculatesize" style="width: auto;">
1855+
</div>
1856+
<div class="form-row">
1857+
<label><i class="fa fa-tag"></i> Skip Update User Size</label>
1858+
<input type="checkbox" id="node-input-skipupdateusersize" style="width: auto;">
1859+
</div>
18011860
<div class="form-row">
18021861
<label><i class="fa fa-tag"></i> Name</label>
18031862
<input type="text" id="node-input-name" placeholder="Name">
@@ -1816,6 +1875,9 @@
18161875
icon: "font-awesome/fa-list",
18171876
defaults: {
18181877
name: { value: "" },
1878+
skipnodered: { value: false },
1879+
skipcalculatesize: { value: false },
1880+
skipupdateusersize: { value: false },
18191881
},
18201882
inputs: 1,
18211883
outputs: 1,

OpenFlowNodeRED/src/nodered/nodes/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export = function (RED: Red) {
3030
RED.nodes.registerType("api upload file", api.upload_file);
3131

3232
RED.nodes.registerType("api list collections", api.list_collections);
33+
RED.nodes.registerType("api drop collection", api.drop_collection);
34+
3335
RED.nodes.registerType("api housekeeping", api.housekeeping);
3436

3537
RED.httpAdmin.get("/api_roles", RED.auth.needsPermission('serial.read'), api.get_api_roles);

OpenFlowNodeRED/src/nodered/nodes/api_nodes.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,10 +1430,43 @@ export class list_collections {
14301430

14311431

14321432

1433+
export interface Idrop_collection {
1434+
name: string;
1435+
collectioname: string;
1436+
}
1437+
export class drop_collection {
1438+
public node: Red = null;
1439+
public name: string;
1440+
constructor(public config: Idrop_collection) {
1441+
RED.nodes.createNode(this, config);
1442+
this.node = this;
1443+
this.name = config.name;
1444+
this.node.on("input", this.oninput);
1445+
this.node.on("close", this.onclose);
1446+
}
1447+
async oninput(msg: any) {
1448+
try {
1449+
this.node.status({});
1450+
let priority: number = 1;
1451+
if (!NoderedUtil.IsNullEmpty(msg.priority)) { priority = msg.priority; }
1452+
const collectionname: any = await Util.EvaluateNodeProperty<string>(this, msg, "collectioname");
1453+
await NoderedUtil.DropCollection({ collectionname, priority });
1454+
this.node.send(msg);
1455+
this.node.status({});
1456+
} catch (error) {
1457+
NoderedUtil.HandleError(this, error, msg);
1458+
}
1459+
}
1460+
onclose() {
1461+
}
1462+
}
1463+
14331464

14341465
export interface Ihousekeeping {
14351466
name: string;
1436-
results: string;
1467+
skipnodered: boolean
1468+
skipcalculatesize: boolean;
1469+
skipupdateusersize: boolean;
14371470
}
14381471
export class housekeeping {
14391472
public node: Red = null;
@@ -1450,8 +1483,10 @@ export class housekeeping {
14501483
let priority: number = 1;
14511484
if (!NoderedUtil.IsNullEmpty(msg.priority)) { priority = msg.priority; }
14521485

1486+
const { skipnodered, skipcalculatesize, skipupdateusersize } = this.config;
1487+
14531488
this.node.status({ fill: "blue", shape: "dot", text: "Running house keeping" });
1454-
await NoderedUtil.HouseKeeping({ jwt: msg.jwt, priority });
1489+
await NoderedUtil.HouseKeeping({ skipnodered, skipcalculatesize, skipupdateusersize, jwt: msg.jwt, priority });
14551490
this.node.send(msg);
14561491
this.node.status({ fill: "green", shape: "dot", text: "Complete" });
14571492
} catch (error) {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.3
1+
1.4.4

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.4.3",
3+
"version": "1.4.4",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)