Importing push tokens
Overview
The following steps are a recipe how to import the push tokens form csv file.
The needed of this script is requested in this ticket SUITEDEV-25068.
The recipe contains the commands while working on the issue
While the import script is working deletion worker duplicate-push-token-cleanup is working also for cleaning duplicate tokens imported
Description of the import-csv-v3
Link to the script import-csv-v3
This script reads a given CSV file and uses the me-client service API (V3 API) to register the
client, assign the token to the client and connect the client to the anonymous contact.
The script can be used to import tokens for
-
mobile push (this is the default) and
-
web push (browsers).
Execution the script in the pod
kubectl run -it --image eu.gcr.io/ems-gap-images/me-push:latest me-push-<name-of-the-pod> -- bash
kubectl cp <import-csv-name>.csv me-push-<name-of-the-pod>:<import-csv-name>.csv
Inside the pod bash
node server/processes/scripts/import-csv-v3/index.js --filename <import-csv-name>.csv --bom true
The script will output imported rows imediately while execution
contactToken xxx
processRecord {
platform: 'android',
hardware_id: 'xxx-xxx',
push_token: 'XXXX',
application_code: 'XXXX-0000',
language: 'en',
last_app_activity: 'XX/XX/XXXX'
}
processRecord {
platform: 'ios',
push_token: 'XXXX',
push_token: 'XXXX',
application_code: 'XXXX-0000',
language: 'en',
last_app_activity: 'XX/XX/XXXX'
}
When the script is done, you will be informed with result like this
- Summary -
Time started: Wed Oct 28 2020 12:42:04 GMT+0000
Time finished: Wed Oct 28 2020 12:42:11 GMT+0000
Duration: 0 minutes
Valid Records in CSV: 47
Invalid Records in CSV: 0
Imported: 47
Skipped: 0
Errors: 0
Problems & Hints
-
Some of the records in the csv file might be without push_token. Those records will fail validation and be automatically filtered out.
-
Maybe some of the push tokens requests will failed while importing and you will get some of these 3 types of errors (ECONNREFUSED, ETIMEDOUT or Bad Gateway)
Steps for resolving the faced errors:
-
You need to find the csv file with errors inside the pod
<import-csv-name>.csv-errors.csv -
You need to generate new csv file with the failing records from the original file
-
for ETIMEDOUT or ECONNREFUSED
grep "ETIMEDOUT or ECONNREFUSED" <import-csv-name>.csv-errors.csv | cut -d ',' -f 4 > failed-ids.txt
fgrep -f failed-ids.txt <import-csv-name>.csv > failed-tokens.csv
-
for Bad Gateway
grep "Bad Gateway" <import-csv-name>.csv-errors.csv | cut -d ',' -f 3 > failed-ids.txt
fgrep -f failed-ids.txt <import-csv-name>.csv > failed-tokens.csv
-
-
We need to copy the first line of the original csv file to the new failed-tokens.csv
platform,hardware_id,push_token,application_code,language,last_app_activity
-
Run the script with the new file
failed-tokens.csv