Skip to content

Instantly share code, notes, and snippets.

@mdimai666
Created April 18, 2018 07:50
Show Gist options
  • Save mdimai666/d7c8c1a79657de25be2e143f72205406 to your computer and use it in GitHub Desktop.
Save mdimai666/d7c8c1a79657de25be2e143f72205406 to your computer and use it in GitHub Desktop.
[
{
"id": "6ca1909c.71f58",
"type": "inject",
"z": "f2af3e46.9dad5",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 123,
"y": 2200,
"wires": [
[
"57cce9fc.daab38"
]
]
},
{
"id": "57cce9fc.daab38",
"type": "function",
"z": "f2af3e46.9dad5",
"name": "send",
"func": "let count = 1000;\nlet i = 0;\nnode.status({});\nflow.set('ddtest1',0);\nlet startTime = new Date();\n\nfunction next(){\n i++;\n if((new Date()) - startTime > 500){\n node.status({text: `in ${i}/${count}`});\n startTime = new Date();\n }\n msg.payload = `indiana ${i}`;\n node.send(msg);\n \n if(i<count)\n setTimeout(function() {\n next(i);\n }, 20);\n else {\n node.status({text: `in ${i}/${count}`});\n }\n}\n\nnext();",
"outputs": 1,
"noerr": 0,
"x": 275,
"y": 2193,
"wires": [
[
"23ebc73b.69b828"
]
]
},
{
"id": "23ebc73b.69b828",
"type": "function",
"z": "f2af3e46.9dad5",
"name": "structurize Log message",
"func": "var jj = global.get('jj'); //JSON safe stringify\n\nvar log = {};\n\nvar uid = global.get('uuid')();\n\nif(typeof msg === 'object'){\n \n if(msg.error){\n var e = msg.error;\n log = {\n title : e.message,\n code: 910,\n source: 'node-red: ' + jj(e.source).slice(0,100),\n body: jj(e),\n json: jj(msg),\n \n }\n }\n else\n try {\n title = msg.title || msg.topic;\n if(title.trim().length<2)\n title = jj(msg).slice(0,100);\n log = {\n code : msg.code || 911,\n source: msg.source || 'node-red',\n title: title,\n body: msg.payload,\n json: jj(msg),\n } \n } catch(err){\n log.json = jj(msg);\n log.body = err.toString();\n }\n} else {\n log = {\n code : msg.code || 913,\n source: 'node-red',\n title: msg.toString().slice(0,100), \n body: (msg),\n } \n}\n\nlog.uid = uid;\nmsg.payload = log;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 495,
"y": 2191,
"wires": [
[
"bd377780.bcff48"
]
]
},
{
"id": "bd377780.bcff48",
"type": "http request",
"z": "f2af3e46.9dad5",
"name": "",
"method": "POST",
"ret": "obj",
"url": "http://localhost:3050/api/logs/add",
"tls": "",
"x": 484,
"y": 2259,
"wires": [
[
"4622c0bc.25793"
]
]
},
{
"id": "3f36dafd.9df346",
"type": "comment",
"z": "f2af3e46.9dad5",
"name": "нагрузочный тест",
"info": "",
"x": 140,
"y": 2124,
"wires": []
},
{
"id": "4622c0bc.25793",
"type": "function",
"z": "f2af3e46.9dad5",
"name": "check",
"func": "\nif(msg.payload && msg.payload.Result===\"OK\") {\n let cx = flow.get('ddtest1');\n msg.payload = cx;\n cx++;\n flow.set('ddtest1',cx);\n node.status({text: `get ${cx}`});\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 671,
"y": 2287,
"wires": [
[]
]
},
{
"id": "b5a3e066.d3be7",
"type": "function",
"z": "f2af3e46.9dad5",
"name": "send some page",
"func": "let count = 10;\nlet i = 0;\nnode.status({});\nflow.set('ddtest2',0);\nlet startTime = new Date();\n\nfunction next(){\n i++;\n if((new Date()) - startTime > 500){\n node.status({text: `in ${i}/${count}`});\n startTime = new Date();\n }\n msg.payload = `req-${i}`;\n node.send(msg);\n \n if(i<count)\n setTimeout(function() {\n next(i);\n }, 50);\n else {\n node.status({text: `in ${i}/${count}`});\n }\n}\n\nnext();",
"outputs": 1,
"noerr": 0,
"x": 295,
"y": 2338,
"wires": [
[
"23573130.ef484e"
]
]
},
{
"id": "816c8c7d.ae993",
"type": "http request",
"z": "f2af3e46.9dad5",
"name": "",
"method": "GET",
"ret": "txt",
"url": "",
"tls": "",
"x": 386,
"y": 2435,
"wires": [
[
"58cdd36f.3ade6c"
]
]
},
{
"id": "58cdd36f.3ade6c",
"type": "function",
"z": "f2af3e46.9dad5",
"name": "check",
"func": "\nif(msg.statusCode && msg.statusCode===200) {\n let cx = flow.get('ddtest2');\n msg.payload = cx;\n cx++;\n flow.set('ddtest2',cx);\n node.status({text: `get ${cx}`});\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 558,
"y": 2432,
"wires": [
[]
]
},
{
"id": "c6a56421.c1b298",
"type": "comment",
"z": "f2af3e46.9dad5",
"name": "Logs",
"info": "",
"x": 133,
"y": 2167,
"wires": []
},
{
"id": "4ab3f33c.6da24c",
"type": "inject",
"z": "f2af3e46.9dad5",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 107,
"y": 2330,
"wires": [
[
"b5a3e066.d3be7"
]
]
},
{
"id": "23573130.ef484e",
"type": "template",
"z": "f2af3e46.9dad5",
"name": "",
"field": "url",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "http://localhost:3050/campaigns/40/?{{payload}}",
"output": "str",
"x": 219,
"y": 2435,
"wires": [
[
"816c8c7d.ae993"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment