-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebsocketFileParseId_Snippet_GPAS.sh
executable file
·32 lines (27 loc) · 1.68 KB
/
WebsocketFileParseId_Snippet_GPAS.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
pid="GPAS"
clientId="GPAS_01"
clientDomain="GPAS"
function worker() {
transactionId="$(echo "$1" | sed -nr 's/.*"transactionId":"([^"]+)".*/\1/p')"
processId="$(echo "$1" | sed -nr 's/.*"processId":"([^"]+)".*/\1/p')"
fileId="$(echo "$1" | sed -nr 's/.*"fileId":"([^"]+)".*/\1/p')"
timestamp="$(echo "$1" | sed -nr 's/.*"createdAt":"([^"]+)".*/\1/p')"
if [ -z "$transactionId" ] || [ -z "$processId" ] || [ -z "$fileId" ]; then return; fi
echo "$transactionId $processId $fileId $timestamp"
curl --silent -X POST -H "x-client-id: $clientId" -H "x-client-domain: $clientDomain" "http://localhost:3000/v1/transactions/$transactionId/processes/$pid"
curl --silent -X POST -H "x-client-id: $clientId" -H "x-client-domain: $clientDomain" -H "x-accessable-by: ClientDomain" -H 'Content-Type: text/csv' --data-binary @<(curl --silent -X GET -H "x-client-id: $clientId" -H "x-client-domain: $clientDomain" "http://localhost:3000/v1/transactions/$transactionId/processes/$processId/files/$fileId" | ../../mosaic-cli-chunked/gpas-cli-chunked.sh) "http://localhost:3000/v1/transactions/$transactionId/processes/$pid/files/$fileId"
}
inbox="$(curl --silent -X GET -H "x-client-id: $clientId" -H "x-client-domain: $clientDomain" "http://localhost:3000/v1/files/?filterUnprocessed=$pid")"
wssince="$(echo "$inbox" | sed -nE '/\n\n/q;s/^Date: (.+)$/\1/p')"
delim="},{"
data="$(echo "$inbox" | sed -E 'N;/\n\n/q;D')$delim"
while [[ $data ]]; do
file="${data%%"$delim"*}"
data="${data#*"$delim"}"
worker "$file"
done
websocat --text --header="x-client-id: $clientId" --header="x-client-domain: $clientDomain" --header="Date: $wssince" - ws://localhost:3000/v1/files | \
while IFS= read file; do
worker "$file"
done