This file contains hidden or 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
name: Deploy Cloud Workflow | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
name: Deploy Cloud Workflow | |
runs-on: ubuntu-18.04 | |
steps: |
This file contains hidden or 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
- getCurrentTime: | |
call: http.get | |
args: | |
url: https://us-central1-workflowsample.cloudfunctions.net/datetime | |
result: currentTime | |
- readWikipedia: | |
call: http.get | |
args: | |
url: https://en.wikipedia.org/w/api.php | |
query: |
This file contains hidden or 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
# Get Cloud Run URL | |
ENDPOINT=$(\ | |
gcloud run services list \ | |
--project=${PROJECT} \ | |
--region=${REGION} \ | |
--platform=managed \ | |
--format="value(status.address.url)" \ | |
--filter="metadata.name=grpc-calculator") | |
ENDPOINT=${ENDPOINT#https://} && echo ${ENDPOINT} |
This file contains hidden or 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
function calculate(call, callback) { | |
const request = call.request; | |
let result; | |
if (request.operation === 'ADD') { | |
result = request.first_operand + request.second_operand; | |
} else { | |
result = request.first_operand - request.second_operand; | |
} | |
callback(null, {result}); | |
} |
This file contains hidden or 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
function main() { | |
const server = new grpc.Server(); | |
server.addService(calculatorProto.Calculator.service, {calculate}); | |
server.bindAsync(`0.0.0.0:${PORT}`, grpc.ServerCredentials.createInsecure(), (error, port) => { | |
if (error) { | |
throw error; | |
} | |
server.start(); | |
}); | |
} |
This file contains hidden or 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
enum Operation { | |
ADD = 0; | |
SUBTRACT = 1; | |
} | |
message BinaryOperation { | |
float first_operand = 1; | |
float second_operand = 2; | |
Operation operation = 3; | |
}; | |
message CalculationResult { |
This file contains hidden or 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
export TRIGGER_NAME=events-cal-trigger | |
export RUN_SERVICE=helloworld-events | |
export PROJECT_NUMBER="$(gcloud projects describe $(gcloud config get-value project) --format='value(projectNumber)')" | |
gcloud eventarc triggers create $TRIGGER_NAME \ | |
--destination-run-service=$RUN_SERVICE \ | |
--service-account=${PROJECT_NUMBER}[email protected] \ | |
--event-filters="type=google.cloud.audit.log.v1.written" \ | |
--event-filters="serviceName=cloudfunctions.googleapis.com" \ | |
--event-filters="methodName=google.cloud.functions.v1.CloudFunctionsService.CreateFunction" |
This file contains hidden or 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
#include <google/cloud/functions/http_request.h> | |
#include <google/cloud/functions/http_response.h> | |
#include <nlohmann/json.hpp> | |
namespace gcf = ::google::cloud::functions; | |
gcf::HttpResponse hello_world_http(gcf::HttpRequest request) { | |
auto greeting = [r = std::move(request)] { | |
auto request_json = nlohmann::json::parse(r.payload(), /*cb=*/nullptr, | |
/*allow_exceptions=*/false); |
This file contains hidden or 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
# Configuration | |
export PROJECT_ID=$(gcloud config get-value core/project) | |
# Deploy Workflow | |
gcloud workflows deploy myFirstWorkflow \ | |
--source=myFirstWorkflow.yaml | |
# Deploy (private) Function | |
gcloud functions deploy runWorkflowFunction \ | |
--runtime nodejs12 \ |
This file contains hidden or 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
const projectId = process.env.PROJECT_ID; | |
/** | |
* Run Workflow Cloud Function | |
*/ | |
exports.runWorkflow = async (req, res) => { | |
if (req.method !== 'POST') { | |
return res.status(405).send('Only POST method is allowed'); | |
} | |
const workflowsAPI = await callWorkflowsAPI(); |