Massive update of Work items state

is there a way to move “bulk” work items from a terminal state (successful, Failed) to retry (or new)?

Not in the ui, but is simple to do using an update document via the api or from nodered.
Not at a computer right now, but will try and remember to get back with an example a little later. If noone else comes with one before me.

Hi,
This is a node red implementation that you can adjust to match your situation. (Select the code and in NodeRed: Crtl-I to import it)

[
    {
        "id": "f5b24d84d568861e",
        "type": "inject",
        "z": "aeaa0fcf13a3d68a",
        "name": "Bulk retry workitems",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "Bulk retry workitems",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 700,
        "wires": [
            [
                "35cedef87d892082"
            ]
        ]
    },
    {
        "id": "35cedef87d892082",
        "type": "function",
        "z": "aeaa0fcf13a3d68a",
        "name": "Prepare DB call",
        "func": "//msg.wiq = \"<your Workitem Queue name>\";\nmsg.wiq = \"example_queue\";\nmsg.collection = \"workitems\";\nmsg.projection = {};\nmsg.query = {\n    \"wiq\": msg.wiq,\n    \"state\": {\n        \"$in\": [\n            \"processing\",\n            \"failed\"\n        ]\n    }\n};\nmsg.numberOfItems = 500;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 700,
        "wires": [
            [
                "402fe91d7798e5d5"
            ]
        ]
    },
    {
        "id": "402fe91d7798e5d5",
        "type": "api get",
        "z": "aeaa0fcf13a3d68a",
        "name": "Get Data",
        "query": "query",
        "querytype": "msg",
        "projection": "{}",
        "projectiontype": "json",
        "top": "500",
        "toptype": "num",
        "skip": 0,
        "skiptype": "num",
        "collection": "collection",
        "collectiontype": "msg",
        "resultfield": "workitems",
        "resultfieldtype": "msg",
        "orderby": "",
        "orderbytype": "str",
        "x": 480,
        "y": 700,
        "wires": [
            [
                "65ff836bf54f8731",
                "55f8ee0b979171df"
            ]
        ]
    },
    {
        "id": "e2a5a6392f4259ad",
        "type": "workitem updateworkitem",
        "z": "aeaa0fcf13a3d68a",
        "name": "retry example_queue",
        "config": "e50b991cfd430219",
        "workitem": "payload",
        "workitemtype": "msg",
        "ignoremaxretries": "true",
        "ignoremaxretriestype": "bool",
        "files": "newfiles",
        "filestype": "msg",
        "priority": "wipriority",
        "prioritytype": "msg",
        "error": "error",
        "errortype": "msg",
        "state": "retry",
        "success_wiq": "success_wiq",
        "success_wiqtype": "msg",
        "failed_wiq": "failed_wiq",
        "failed_wiqtype": "msg",
        "nextrun": "nextrun",
        "nextruntype": "msg",
        "x": 760,
        "y": 780,
        "wires": [
            [
                "55f8ee0b979171df"
            ]
        ]
    },
    {
        "id": "9757c68ac94709d2",
        "type": "debug",
        "z": "aeaa0fcf13a3d68a",
        "name": "END",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 950,
        "y": 680,
        "wires": []
    },
    {
        "id": "ad24bcbb20f68122",
        "type": "switch",
        "z": "aeaa0fcf13a3d68a",
        "name": "",
        "property": "wiq",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "example_queue",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 570,
        "y": 800,
        "wires": [
            [
                "e2a5a6392f4259ad"
            ],
            [
                "303153ee664ac199",
                "55f8ee0b979171df"
            ]
        ]
    },
    {
        "id": "303153ee664ac199",
        "type": "debug",
        "z": "aeaa0fcf13a3d68a",
        "name": "Unknown workitem queue",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 820,
        "wires": []
    },
    {
        "id": "65ff836bf54f8731",
        "type": "debug",
        "z": "aeaa0fcf13a3d68a",
        "name": "debug 25",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 580,
        "y": 640,
        "wires": []
    },
    {
        "id": "55f8ee0b979171df",
        "type": "array-loop",
        "z": "aeaa0fcf13a3d68a",
        "name": "workitems",
        "key": "al55f8ee0b979171df",
        "keyType": "msg",
        "reset": true,
        "resetValue": "value-null",
        "array": "workitems",
        "arrayType": "msg",
        "x": 720,
        "y": 700,
        "wires": [
            [
                "9757c68ac94709d2"
            ],
            [
                "ad24bcbb20f68122"
            ]
        ]
    },
    {
        "id": "e50b991cfd430219",
        "type": "iworkitemqueue-config",
        "wiq": "example_queue",
        "wiqid": "",
        "name": "example_queue"
    }
]

You would just have to replace example_queue with your queue name. (And check the states you query for: in the example: failed and processing)
And finally in the Update Workitem Node select the correct queue in the config field.

It will get all workitems of specified queue with states “processing” or “failed”.
It will call retry and ignore the max retries setting.

I see that I have used an imported NodeRed pachage (node-red-contrib-loop-processing)
Install via the Pallet, it is very convenient.
Cheers,

Rutger

4 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.