{ "status" : "CANCELED" }
1 #!/bin/bash
2
3 # Cancel all running instances of a given workflow definition
4 # USE WITH CAUTION!
5
6 USER=p481810
7 COOKIES=cookiejar-${USER}.dat
8 INSTANCEDATA=instances.dat
9 TOKENDATA=headers.dat
10 DEFINITIONID=$1
11 WFS_API_ROOT=https://bpmworkflowruntimewfs-${USER}trial.hanatrial.ondemand.com/workflow-service/rest
12 STATUSPAYLOAD={\"status\":\"CANCELED\"}
13
14 # Abort if no definition ID has been specified
15 [ -z "$DEFINITIONID" ] && echo Specify a definition ID && exit 1
16
17 echo WARNING: This will cancel ALL instances for workflow definition \"${DEFINITIONID}\"
18 echo Please enter password for $USER
19 read -s PASS
20
21 rm -f $INSTANCEDATA
22 rm -f $TOKENDATA
23
24
25 # Retrieve the RUNNING instances for the given workflow definition
26 curl \
27 --user $USER:$PASS \
28 --output $INSTANCEDATA \
29 --silent \
30 "$WFS_API_ROOT/v1/workflow-instances?definitionId=${DEFINITIONID}&status=RUNNING"
31
32
33 # Retrieve CSRF token
34 curl \
35 --user $USER:$PASS \
36 --header "X-CSRF-Token: Fetch" \
37 --cookie-jar $COOKIES \
38 --verbose \
39 "$WFS_API_ROOT/v1/xsrf-token" 2> $TOKENDATA
40
41 TOKEN=`grep '< X-CSRF-Token' $TOKENDATA | awk '{print $3}'`
42
43
44 # Process each instance ID - send PATCH with cancel status
45 for INSTANCEID in `jq --raw-output '.[] .id' $INSTANCEDATA`; do
46 echo Canceling $INSTANCEID
47 curl \
48 --user $USER:$PASS \
49 --request PATCH \
50 --header "X-CSRF-Token: $TOKEN" \
51 --header "Content-Type: application/json" \
52 --cookie $COOKIES \
53 --data $STATUSPAYLOAD \
54 "$WFS_API_ROOT/v1/workflow-instances/${INSTANCEID}"
55 sleep 0.5
56
57 done
< X-CSRF-Token: F1F2B62E97BB0CF95AB126AE732E3E15
[{"id":"6f23fba7-34c9-11e8-b586-00163e5a9e8b","definitionId":"untappdrecommendation","definitionVersion":"37","subject
":"Untappd Recommendation","status":"RUNNING","businessKey":"2506750","startedAt":"2018-03-31T09:53:59.251Z","startedB
y":"P481810","completedAt":null},{"id":"6e9b1c8b-34c9-11e8-b586-00163e5a9e8b","definitionId":"untappdrecommendation","
definitionVersion":"37","subject":"Untappd Recommendation","status":"RUNNING","businessKey":"2544284","startedAt":"201
8-03-31T09:53:58.354Z","startedBy":"P481810","completedAt":null}]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
13 | |
10 | |
9 | |
9 | |
8 | |
7 | |
7 | |
7 | |
6 |