-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composer: Move 'triggering DAGs' sample to GitHub. #716
Conversation
Note: as this is moving code as-is from cloud.google.com, I don't add tests in this PR. The only changes I made were to fix the linter errors. I have an open bug 111401746 to fix the error handling code and plan to add unit tests at that time. |
Codecov Report
@@ Coverage Diff @@
## master #716 +/- ##
=======================================
Coverage 55.17% 55.17%
=======================================
Files 1 1
Lines 58 58
=======================================
Hits 32 32
Misses 26 26 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply these comments throughout your PR.
|
||
'use strict'; | ||
|
||
// [START composer_trigger] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: functions region tags are (usually) prefixed with functions_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to, but are you a samples lead in go/samples-tracker? I don't have permissions to make functions samples there.
exports.triggerDag = function triggerDag (event, callback) { | ||
// Fill in your Composer environment information here. | ||
|
||
// The project that holds your function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - typically:
- we only show the contents of a function within a sample (i.e. we omit the function signature)
- we pass in any required values as parameters
- we include definitions of those values in the body of the function, but they are commented out
Apply this comment throughout your PR (if you choose to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even for a cloud functions sample? This sample is intended to be copy-pasted into the cloud functions web UI, so I believe the function signature is necessary.
const DAG_NAME = 'composer_sample_trigger_response_dag'; | ||
|
||
// Other constants | ||
const WEBSERVER_URL = 'https://' + WEBSERVER_ID + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use template literals to construct strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
// Make the request | ||
authorizeIap( | ||
CLIENT_ID, PROJECT_ID, USER_AGENT, | ||
function iapAuthorizationCallback (err, jwt, idToken) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use promises instead of callbacks here? (Both versions of Node on GCF support promises, though only Node 8 supports async/await.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I switched to the node-fetch
library which does support promises.
|
||
const SERVICE_ACCOUNT = [projectId, '@appspot.gserviceaccount.com'].join(''); | ||
|
||
var options = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use const
or let
instead of var
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in new node-fetch
logic.
Sample was originally hard-coded in HTML at https://cloud.google.com/composer/docs/how-to/using/triggering-with-gcf
322ee96
to
677cf79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving the migration as original author of this sample code.
* Composer: Move 'triggering DAGs' sample to GitHub. Sample was originally hard-coded in HTML at https://cloud.google.com/composer/docs/how-to/using/triggering-with-gcf * Use node-fetch for promises in HTTP requests.
🤖 I have created a release *beep* *boop* --- ## [4.0.0](googleapis/nodejs-video-intelligence@v3.4.1...v4.0.0) (2022-06-29) ### ⚠ BREAKING CHANGES * update library to use Node 12 (#714) * field ObjectTrackingAnnotation.segment moved into oneof, added track_id (#704) ### Features * field ObjectTrackingAnnotation.segment moved into oneof, added track_id ([#704](googleapis/nodejs-video-intelligence#704)) ([b55757b](googleapis/nodejs-video-intelligence@b55757b)) * support regapic LRO ([#720](googleapis/nodejs-video-intelligence#720)) ([903e5ca](googleapis/nodejs-video-intelligence@903e5ca)) ### Bug Fixes * fixes for dynamic routing and streaming descriptors ([#716](googleapis/nodejs-video-intelligence#716)) ([853d91e](googleapis/nodejs-video-intelligence@853d91e)) ### Build System * update library to use Node 12 ([#714](googleapis/nodejs-video-intelligence#714)) ([a9fbbcd](googleapis/nodejs-video-intelligence@a9fbbcd)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [4.0.0](googleapis/nodejs-video-intelligence@v3.4.1...v4.0.0) (2022-06-29) ### ⚠ BREAKING CHANGES * update library to use Node 12 (#714) * field ObjectTrackingAnnotation.segment moved into oneof, added track_id (#704) ### Features * field ObjectTrackingAnnotation.segment moved into oneof, added track_id ([#704](googleapis/nodejs-video-intelligence#704)) ([b55757b](googleapis/nodejs-video-intelligence@b55757b)) * support regapic LRO ([#720](googleapis/nodejs-video-intelligence#720)) ([903e5ca](googleapis/nodejs-video-intelligence@903e5ca)) ### Bug Fixes * fixes for dynamic routing and streaming descriptors ([#716](googleapis/nodejs-video-intelligence#716)) ([853d91e](googleapis/nodejs-video-intelligence@853d91e)) ### Build System * update library to use Node 12 ([#714](googleapis/nodejs-video-intelligence#714)) ([a9fbbcd](googleapis/nodejs-video-intelligence@a9fbbcd)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [4.0.0](googleapis/nodejs-video-intelligence@v3.4.1...v4.0.0) (2022-06-29) ### ⚠ BREAKING CHANGES * update library to use Node 12 (#714) * field ObjectTrackingAnnotation.segment moved into oneof, added track_id (#704) ### Features * field ObjectTrackingAnnotation.segment moved into oneof, added track_id ([#704](googleapis/nodejs-video-intelligence#704)) ([b55757b](googleapis/nodejs-video-intelligence@b55757b)) * support regapic LRO ([#720](googleapis/nodejs-video-intelligence#720)) ([903e5ca](googleapis/nodejs-video-intelligence@903e5ca)) ### Bug Fixes * fixes for dynamic routing and streaming descriptors ([#716](googleapis/nodejs-video-intelligence#716)) ([853d91e](googleapis/nodejs-video-intelligence@853d91e)) ### Build System * update library to use Node 12 ([#714](googleapis/nodejs-video-intelligence#714)) ([a9fbbcd](googleapis/nodejs-video-intelligence@a9fbbcd)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sample was originally hard-coded in HTML at
https://cloud.google.com/composer/docs/how-to/using/triggering-with-gcf
Python code for target DAG is also being moved to GitHub in GoogleCloudPlatform/python-docs-samples#1645
@TrevorEdwards Please review.