-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'couchbase/unstable' into HEAD
http://ci-eventing.northscale.in/eventing-04.07.2019-02.38.pass.html Change-Id: Ie364b58f9f6ede79eed5488b99268be26ba556fd
- Loading branch information
Showing
18 changed files
with
24,533 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[ | ||
{ | ||
"appcode": "// This function runs at the promised delivery date to see status of package\nfunction statusCheck(context) {\n var label = labels_bucket[context];\n if (label.delivered) return;\n sendEmail('someone@example.com', // Put in a valid email address here\n label.number,\n label.exceptions);\n}\n\n// This function executes whenever a label is created or modified\nfunction OnUpdate(label, meta) {\n if (label.delivered) return; // ignore packages that are already delivered\n var deliver_by = new Date(label.deliver_by);\n log(\"Delayed package, sending email: \", label.number);\n createTimer(statusCheck, // function to run when timer fires\n deliver_by, // date for timer to fire\n meta.id, // unique key set to document key\n label.number); // user context set to label number\n}\n\n// This function sends an email with details of the delay\nfunction sendEmail(to, reference, reasons) {\n var msg = 'We are sorry, your package ' + reference + ' is delayed due to following reasons:<p>';\n for (var i = 0; reasons && i < reasons.length; i++) {\n msg += 'Exception: [' + reasons[i].date + '] - ' + reasons[i].description + '<br>';\n }\n msg += '<p>Please call us at 1-800-555-1212 if you need further information';\n var email = {\n 'personalizations': [{'to': [{'email': to}]}],\n 'from': {'email': 'cb.ci.bot@gmail.com'},\n 'subject': 'Package delivery delay: ' + reference,\n 'content': [{'type': 'text/html', value: msg}]\n };\n var response = curl('POST', mailer_binding, {body: email});\n if (response.status < 200 || response.status >= 300) {\n log(\"Failed to send email: \", response);\n }\n}", | ||
"depcfg": { | ||
"buckets": [ | ||
{ | ||
"alias": "labels_bucket", | ||
"bucket_name": "labels", | ||
"access": "r" | ||
} | ||
], | ||
"curl": [ | ||
{ | ||
"hostname": "https://api.sendgrid.com/v3/mail/send", | ||
"value": "mailer_binding", | ||
"auth_type": "bearer", | ||
"username": "", | ||
"password": "", | ||
"bearer_key": "", | ||
"allow_cookies": true, | ||
"validate_ssl_certificate": true | ||
} | ||
], | ||
"metadata_bucket": "meta", | ||
"source_bucket": "labels" | ||
}, | ||
"version": "evt-6.5.0-0000-ee", | ||
"function_id": 1792638007, | ||
"id": 0, | ||
"function_instance_id": "RsaIK3", | ||
"appname": "EmailOnDelay", | ||
"settings": { | ||
"dcp_stream_boundary": "everything", | ||
"deadline_timeout": 62, | ||
"deployment_status": false, | ||
"description": "Send an email when a package misses promised delivery date", | ||
"execution_timeout": 60, | ||
"log_level": "INFO", | ||
"processing_status": false, | ||
"user_prefix": "eventing", | ||
"using_timer": true, | ||
"worker_count": 3 | ||
}, | ||
"using_timer": false, | ||
"src_mutation": false | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## About | ||
This demo shows how to use eventing to send an email if a package misses committed delivery date. | ||
|
||
## Insturctions | ||
1. Generate some sample data by running 'go run \*.go -args 10 > data.json' (generates 10 docs) | ||
1. Create two buckets, one called labels (to hold the dat) and another called meta (for eventing metadata) | ||
1. Import the Handler\_EmailOnDelay.json file | ||
1. Put in a suitable SendGrid API key into the curl binding 'mailer\_binding' | ||
1. Change the email address in the handler to your own email | ||
1. Import it using: cbimport json -c localhost -u Administrator -p password -b labels -f list -d file://./data.json -g '%number%' | ||
1. Deploy the handler | ||
1. Now open a document with exceptions in labels bucket, and delete the 'delivered' field | ||
1. At the promised delivery date, an email will be sent indicating delay | ||
|
||
## Sample Data | ||
Run main.go to generate data. Below is a sample document: | ||
``` js | ||
{ | ||
"number": "1Z 174 JP7 03 4463 8651", | ||
"sender_name": "Mindi Oatley", | ||
"sender_company": "LegiNation, Company", | ||
"sender_addr": { | ||
"street": "3123 Mallorca Way", | ||
"city": "Howell", | ||
"state": "NJ", | ||
"zip": "07010-4725" | ||
}, | ||
"declared_value": 0, | ||
"description": "2010 Ford Explorer Xlt 4dr, 2wd, Suv Mid Size", | ||
"receiver_name": "Soo Benett", | ||
"receiver_company": "DemystData Inc", | ||
"receiver_addr": { | ||
"street": "394 Hulbert Aly", | ||
"city": "Rochester", | ||
"state": "NY", | ||
"zip": "14558-0612" | ||
}, | ||
"weight_lb": 0.1, | ||
"dimensions_in": "15 x 9.5 x 0.1", | ||
"created": "05/10/2019 10:15 AM", | ||
"picked_up": "05/12/2019 04:46 PM", | ||
"deliver_by": "05/12/2019 09:30 AM", | ||
"exceptions": [ | ||
{ | ||
"date": "05/12/2019 09:05 AM", | ||
"description": "THIS SHIPMENT WAS KEYED WITH THE INCORRECT SERVICE LEVEL AT THE ORIGIN ODC SITE" | ||
}, | ||
{ | ||
"date": "05/13/2019 05:51 PM", | ||
"description": "THE FREIGHT SHIPMENT HAS ARRIVED AT THE CARRIER DESTINATION FACILITY" | ||
}, | ||
{ | ||
"date": "05/13/2019 12:54 PM", | ||
"description": "PKG DELAYED - NO CONNECTION TO CUSTOMS" | ||
}, | ||
{ | ||
"date": "05/14/2019 01:43 PM", | ||
"description": "UNAUTHORIZED OVERWEIGHT/OVERSIZED SHIPMENT; PRIOR AUTHORIZATION REQUIRED" | ||
} | ||
] | ||
} | ||
``` | ||
|
Oops, something went wrong.