Skip to content

Commit 045326c

Browse files
karagulamoseduardoboucaserezrokahkodiakhq[bot]
authoredFeb 4, 2022
feat(functions): add scheduled functions templates (#4145)
* feat: add SF template for javascript & typescript * Update src/functions-templates/javascript/scheduled-function/package.json Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> * Update src/functions-templates/javascript/scheduled-function/{{name}}.js Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> * Update src/functions-templates/typescript/scheduled-function/package.json Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> * Update src/functions-templates/typescript/scheduled-function/{{name}}.ts Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> * fix: applied suggested improvements * fix: prefer inferred types over explicit ones * chore: add helpful comments to SF-JS template * chore: add helpful comments to SF-TS template * chore: provide meaningful comments and examples Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com> Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 49708c2 commit 045326c

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
name: 'scheduled-function',
3+
priority: 1,
4+
description: 'Basic implementation of a scheduled function in JavaScript.',
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "{{name}}",
3+
"version": "1.0.0",
4+
"description": "netlify functions:create - scheduled function in JavaScript",
5+
"main": "{{name}}.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"netlify",
11+
"serverless",
12+
"javascript",
13+
"schedule"
14+
],
15+
"author": "Netlify",
16+
"license": "MIT",
17+
"dependencies": {
18+
"@netlify/functions": "^0.11.0"
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { schedule } = require('@netlify/functions')
2+
3+
// To learn about scheduled functions and supported cron extensions,
4+
// see: https://ntl.fyi/sched-func
5+
module.exports.handler = schedule('* * * * *', async (event) => {
6+
const eventBody = JSON.parse(event.body)
7+
console.log(`Next function run at ${eventBody.next_run}.`)
8+
9+
return {
10+
statusCode: 200,
11+
}
12+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
name: 'scheduled-function',
3+
priority: 1,
4+
description: 'Basic implementation of a scheduled function in TypeScript.',
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "{{name}}",
3+
"version": "1.0.0",
4+
"description": "netlify functions:create - scheduled function in TypeScript",
5+
"main": "{{name}}.ts",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"netlify",
11+
"serverless",
12+
"typescript",
13+
"schedule"
14+
],
15+
"author": "Netlify",
16+
"license": "MIT",
17+
"dependencies": {
18+
"@netlify/functions": "^0.11.0",
19+
"@types/node": "^14.18.9",
20+
"typescript": "^4.5.5"
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { schedule } from '@netlify/functions';
2+
3+
// To learn about scheduled functions and supported cron extensions,
4+
// see: https://ntl.fyi/sched-func
5+
export const handler = schedule("@hourly", (event) => {
6+
const eventBody = JSON.parse(event.body);
7+
console.log(`Next function run at ${eventBody.next_run}.`);
8+
9+
return {
10+
statusCode: 200
11+
};
12+
});

1 commit comments

Comments
 (1)

github-actions[bot] commented on Feb 4, 2022

@github-actions[bot]

📊 Benchmark results

Package size: 363 MB

Please sign in to comment.