Skip to content
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

migrate code from googleapis/nodejs-scheduler #2848

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6a43cfe
initial commit
jkwlui Nov 13, 2018
f7f5848
chore: clean up lint rules (#2)
JustinBeckwith Nov 21, 2018
7d569f6
Release v0.1.1 (#21)
jkwlui Dec 7, 2018
e517173
Release v0.1.2 (#29)
jkwlui Jan 3, 2019
132ed19
docs(samples): Add App Engine Target sample (#33)
averikitsch Jan 25, 2019
dce58b8
chore(deps): update dependency mocha to v6
renovate[bot] Feb 19, 2019
e6c0c1a
chore(deps): update dependency supertest to v4
renovate[bot] Mar 9, 2019
7c36507
Release v0.2.0 (#61)
JustinBeckwith Mar 11, 2019
c9204a3
Release v0.3.0 (#71)
jkwlui Apr 4, 2019
9a1c5e2
refactor: use execSync for tests (#69)
JustinBeckwith Apr 4, 2019
cabfa83
refactor: wrap execSync with encoding: utf-8 (#73)
jkwlui Apr 5, 2019
1a103e1
docs: update to useful quickstart
bcoe Apr 24, 2019
906b36e
test: add a smoke test and perform cleanup (#80)
JustinBeckwith Apr 30, 2019
f595e20
chore: release 1.0.0 (#95)
bcoe May 13, 2019
ec53613
chore: release 1.1.0 (#105)
yoshi-automation Jun 5, 2019
c56a03e
chore(deps): npm audit fix (#106)
JustinBeckwith Jun 11, 2019
665887c
chore: release 1.1.1 (#109)
yoshi-automation Jun 14, 2019
2ba9bd1
chore: release 1.1.2 (#112)
yoshi-automation Jun 27, 2019
55789f7
chore: release 1.1.3 (#121)
yoshi-automation Aug 5, 2019
a7536d3
chore: release 1.1.4 (#123)
yoshi-automation Aug 26, 2019
14c5938
chore: release 1.2.0 (#128)
yoshi-automation Sep 6, 2019
e64f9f1
chore: release 1.3.2 (#148)
release-please[bot] Oct 22, 2019
abf3b04
chore: release 1.3.3 (#157)
release-please[bot] Nov 15, 2019
a2c060e
chore: update license headers (#164)
JustinBeckwith Nov 25, 2019
7dc8bce
refactor: use explicit mocha imports (#173)
JustinBeckwith Dec 30, 2019
c8fe1df
chore: release 1.4.0
release-please[bot] Jan 6, 2020
1212041
chore(deps): update dependency mocha to v7 (#175)
renovate-bot Jan 6, 2020
64ea960
chore: release 1.4.1 (#177)
release-please[bot] Jan 9, 2020
9905bfd
fix(samples): delete stale comment from sample (#182)
fhinkel Jan 24, 2020
76cc46e
chore: release 1.4.2 (#186)
release-please[bot] Jan 30, 2020
82d291a
chore: release 1.4.3 (#197)
release-please[bot] Feb 12, 2020
baf0390
chore: release 1.5.0 (#203)
release-please[bot] Mar 3, 2020
e003fac
chore: release 1.6.0 (#213)
release-please[bot] Mar 11, 2020
84b4505
feat!: drop node8 support, support for async iterators (#227)
alexander-fenster Mar 31, 2020
15054f6
fix: drop unused files from package (#242)
JustinBeckwith Apr 14, 2020
33ca8c1
chore: release 2.0.0 (#228)
release-please[bot] Jun 2, 2020
3e6e8b8
chore(deps): update dependency mocha to v8 (#259)
renovate-bot Jun 11, 2020
cbe7bd0
chore: release 2.1.0 (#260)
release-please[bot] Jun 16, 2020
d7c9e28
chore: release 2.1.1 (#264)
release-please[bot] Jul 7, 2020
921b008
docs(samples): add sample for updateJob (#265)
kelsk Sep 17, 2020
47e4905
chore(deps): update dependency supertest to v6 (#308)
renovate-bot Nov 19, 2020
ec304e1
chore: release 2.1.2 (#312)
release-please[bot] Dec 2, 2020
881c6ad
chore: release 2.1.3 (#315)
release-please[bot] Dec 9, 2020
61bc5e3
chore: release 2.2.0 (#320)
release-please[bot] Jan 12, 2021
a5ac2de
test: intentional break to test flake bot (#324)
bcoe Jan 26, 2021
6ea4e6b
Revert "test: intentional break to test flake bot (#324)" (#326)
bcoe Jan 26, 2021
2b30a5c
chore: release 2.2.1 (#359)
release-please[bot] May 13, 2021
8a52c36
chore: release 2.2.2 (#368)
release-please[bot] Jun 3, 2021
77501d0
chore: release 2.2.3 (#378)
release-please[bot] Jun 22, 2021
3578333
chore: release 2.2.4 (#386)
release-please[bot] Jun 30, 2021
611dcdc
test: run system and sample tests with cloud build (#383)
JustinBeckwith Jul 1, 2021
34a57ae
chore: release 2.2.5 (#389)
release-please[bot] Jul 19, 2021
a584490
chore: release 2.2.6 (#398)
release-please[bot] Aug 17, 2021
0a05328
chore: release 2.3.0 (#400)
release-please[bot] Sep 10, 2021
9e5b653
docs(samples): add auto-generated samples for Node with api short nam…
gcf-owl-bot[bot] Oct 5, 2021
277cded
chore: update sample (#449)
averikitsch May 13, 2022
3c915fb
build!: update library to use Node 12 (#452)
sofisl May 20, 2022
92b317d
chore(main): release 3.0.0 (#453)
release-please[bot] May 26, 2022
cfb2608
chore(main): release 3.0.1 (#458)
release-please[bot] Jun 30, 2022
5e534ff
chore(main): release 3.0.2 (#462)
release-please[bot] Aug 2, 2022
9ffb06c
chore(main): release 3.0.3 (#466)
release-please[bot] Aug 26, 2022
64b9fcb
chore(main): release 3.0.4 (#470)
release-please[bot] Sep 22, 2022
1d53730
chore(main): release 3.0.5 (#482)
release-please[bot] Nov 11, 2022
f3180d4
Merge remote-tracking branch 'migration/main' into nodejs-scheduler-m…
Nov 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scheduler/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
no-console: off
43 changes: 43 additions & 0 deletions scheduler/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use strict';

// [START cloud_scheduler_app]
const express = require('express');
const bodyParser = require('body-parser');

const app = express();
app.use(bodyParser.raw());

// Define relative URI for job endpoint
app.post('/log_payload', (req, res) => {
// Log the job payload
const message = req.body.toString('utf8');
console.log(`Received job with payload: ${message}`);
res.send(`Printed job with payload: ${message}`).end();
});
// [END cloud_scheduler_app]

app.get('/', (req, res) => {
res.status(200).send('Hello, World!').end();
});

// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});

module.exports = app;
18 changes: 18 additions & 0 deletions scheduler/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START cloud_scheduler_yaml]
runtime: nodejs8
service: my-service
# [END cloud_scheduler_yaml]
67 changes: 67 additions & 0 deletions scheduler/createJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// sample-metadata:
// title: Create Job
// description: Create a job that posts to /log_payload on an App Engine service.
// usage: node createJob.js [project-id] [location-id] [app-engine-service-id]

/**
* Create a job with an App Engine target via the Cloud Scheduler API
*/
async function createJob(projectId, locationId, serviceId) {
// [START cloud_scheduler_create_job]
const scheduler = require('@google-cloud/scheduler');

// Create a client.
const client = new scheduler.CloudSchedulerClient();

// TODO(developer): Uncomment and set the following variables
// const projectId = "PROJECT_ID"
// const locationId = "LOCATION_ID"
// const serviceId = "my-serivce"

// Construct the fully qualified location path.
const parent = client.locationPath(projectId, locationId);

// Construct the request body.
const job = {
appEngineHttpTarget: {
appEngineRouting: {
service: serviceId,
},
relativeUri: '/log_payload',
httpMethod: 'POST',
body: Buffer.from('Hello World'),
},
schedule: '* * * * *',
timeZone: 'America/Los_Angeles',
};

const request = {
parent: parent,
job: job,
};

// Use the client to send the job creation request.
const [response] = await client.createJob(request);
console.log(`Created job: ${response.name}`);
// [END cloud_scheduler_create_job]
}

const args = process.argv.slice(2);
createJob(...args).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
48 changes: 48 additions & 0 deletions scheduler/deleteJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// sample-metadata:
// title: Delete Job
// description: Delete a job by its ID.
// usage: node deleteJob.js [project-id] [location-id] [job-id]

/**
* Delete a job via the Cloud Scheduler API
*/
async function deleteJob(projectId, locationId, jobId) {
// [START cloud_scheduler_delete_job]
const scheduler = require('@google-cloud/scheduler');

// Create a client.
const client = new scheduler.CloudSchedulerClient();

// TODO(developer): Uncomment and set the following variables
// const projectId = "PROJECT_ID"
// const locationId = "LOCATION_ID"
// const jobId = "JOB_ID"

// Construct the fully qualified location path.
const job = client.jobPath(projectId, locationId, jobId);

// Use the client to send the job creation request.
await client.deleteJob({name: job});
console.log('Job deleted.');
// [END cloud_scheduler_delete_job]
}

const args = process.argv.slice(2);
deleteJob(...args).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
26 changes: 26 additions & 0 deletions scheduler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "nodejs-scheduler-samples",
"private": true,
"main": "quickstart.js",
"engines": {
"node": ">=12.0.0"
},
"files": [
"*.js"
],
"license": "Apache-2.0",
"scripts": {
"start": "node app.js",
"test": "mocha --timeout 10000 --exit"
},
"dependencies": {
"@google-cloud/scheduler": "^3.0.5",
"body-parser": "^1.18.3",
"express": "^4.16.4"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.0.0",
"supertest": "^6.0.0"
}
}
62 changes: 62 additions & 0 deletions scheduler/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// sample-metadata:
// title: Quickstart
// description: POST "Hello World" to a URL every minute.
// usage: node quickstart.js [project-id] [location-id] [url]

async function main(projectId, locationId, url) {
// [START scheduler_quickstart]
// const projectId = "PROJECT_ID"
// const locationId = "LOCATION_ID" // see: https://cloud.google.com/about/locations/
// const url = "https://postb.in/..." // where should we say hello?

const scheduler = require('@google-cloud/scheduler');

// Create a client.
const client = new scheduler.CloudSchedulerClient();

// Construct the fully qualified location path.
const parent = client.locationPath(projectId, locationId);

// Construct the request body.
const job = {
httpTarget: {
uri: url,
httpMethod: 'POST',
body: Buffer.from('Hello World'),
},
schedule: '* * * * *',
timeZone: 'America/Los_Angeles',
};

const request = {
parent: parent,
job: job,
};

// Use the client to send the job creation request.
const [response] = await client.createJob(request);
console.log(`Created job: ${response.name}`);
// [END scheduler_quickstart]
}

const args = process.argv.slice(2);
main(...args).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
70 changes: 70 additions & 0 deletions scheduler/test/test.samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {CloudSchedulerClient} = require('@google-cloud/scheduler');
const {assert} = require('chai');
const {describe, it, before} = require('mocha');
const cp = require('child_process');
const supertest = require('supertest');
const app = require('../app.js');
const request = supertest(app);

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const LOCATION_ID = process.env.LOCATION_ID || 'us-central1';
const SERVICE_ID = 'my-service';

describe('Cloud Scheduler Sample Tests', () => {
let jobName;
let PROJECT_ID;

before(async () => {
const client = new CloudSchedulerClient();
PROJECT_ID = await client.getProjectId();
});

it('should create and delete a scheduler job', async () => {
const stdout = execSync(
`node createJob.js ${PROJECT_ID} ${LOCATION_ID} ${SERVICE_ID}`
);
assert.match(stdout, /Created job/);
jobName = stdout.split('/').pop();
});

it('should update a scheduler job', async () => {
const stdout = execSync(
`node updateJob.js ${PROJECT_ID} ${LOCATION_ID} ${jobName}`
);
assert.match(stdout, /Updated job/);
});

it('should delete a scheduler job', async () => {
const stdout = execSync(
`node deleteJob.js ${PROJECT_ID} ${LOCATION_ID} ${jobName}`
);
assert.match(stdout, /Job deleted/);
});
});

describe('Server should respond to /log_payload', () => {
it('should log the payload', done => {
const body = Buffer.from('test');
request
.post('/log_payload')
.type('raw')
.send(body)
.expect(200, /Printed job/, done);
});
});
Loading