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

feat: add local dev experience for scheduled functions #3689

Merged
merged 39 commits into from
Jan 28, 2022

Conversation

netlify-team-account-1
Copy link
Contributor

🎉 Thanks for submitting a pull request! 🎉

Summary

This PR adds special behaviour for scheduled functions. To mimic planned production behaviour, the local dev environment will not accept HTTP calls to scheduled functions. It will accept calls made through ntl functions:invoke.

A picture of a cute animal (not mandatory, but encouraged)

@netlify-team-account-1 netlify-team-account-1 added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Nov 23, 2021
@github-actions
Copy link

github-actions bot commented Nov 23, 2021

📊 Benchmark results

Comparing with 40b1cf9

Package size: 360 MB

⬆️ 0.01% increase vs. 40b1cf9

^  359 MB  359 MB  359 MB  359 MB  357 MB  357 MB  357 MB  357 MB  357 MB  357 MB  357 MB  357 MB  360 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Left a few minor comments.

src/lib/functions/netlify-function.js Outdated Show resolved Hide resolved
src/lib/functions/schedule.js Outdated Show resolved Hide resolved
src/lib/functions/server.js Outdated Show resolved Hide resolved
tests/command.functions.test.js Outdated Show resolved Hide resolved
@Skn0tt Skn0tt force-pushed the scheduled-jobs-endpoint branch from 93878c1 to 3fa4c14 Compare November 23, 2021 13:20
eduardoboucas
eduardoboucas previously approved these changes Dec 13, 2021
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Once we bring this branch up-to-date and get the tests passing, I think we're good to go.

@Skn0tt Skn0tt force-pushed the scheduled-jobs-endpoint branch from 36b6c20 to c14699b Compare December 20, 2021 09:27
@netlify-team-account-1
Copy link
Contributor Author

77ef972 updates to the prerelease of netlify/zip-it-and-ship-it#899 (comment) to move this PR forward

eduardoboucas
eduardoboucas previously approved these changes Jan 5, 2022
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments, none of them blocking for the beta launch.

src/lib/functions/server.js Outdated Show resolved Hide resolved
src/commands/functions/functions-invoke.js Show resolved Hide resolved
src/commands/functions/functions-invoke.js Outdated Show resolved Hide resolved
src/commands/functions/functions-invoke.js Outdated Show resolved Hide resolved
let headers = {}
const headers = {
'user-agent': 'netlify-cli',
}
let body = {}

if (eventTriggeredFunctions.has(functionToTrigger)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think scheduled functions should fall on this branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@netlify-team-account-1
Copy link
Contributor Author

netlify-team-account-1 commented Jan 24, 2022

we decided to move forward with the change. let's get this shipped! 🚢 @eduardoboucas @lukasholzer would love another review :)

@lukasholzer
Copy link
Collaborator

Something is killing the tests: Command was killed with SIGKILL (Forced termination):

lukasholzer
lukasholzer previously approved these changes Jan 26, 2022
Copy link
Collaborator

@lukasholzer lukasholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good! Nice PR 🐳, some small nit pick

@@ -129,6 +130,13 @@ const getFunctionToTrigger = function (options, argumentName) {
return argumentName
}

const getNextRun = function (schedule) {
const cron = CronParser.parseExpression(schedule, {
tz: 'Etc/UTC',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we document that somewhere that we rely here un UTC and not on the users timezone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will be document in the Labs docs.

src/lib/functions/runtimes/js/builders/zisi.js Outdated Show resolved Hide resolved

const handleScheduledFunction = ({ error, request, response, result }) => {
const acceptsHtml = request.headers.accept && request.headers.accept.includes('text/html')
const paragraph = (text) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I think you can move this out of this function as you don't need the outer context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const { formatLambdaError } = require('./utils')

const handleScheduledFunction = ({ error, request, response, result }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please write a small unit test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!
6015fd6

Co-authored-by: Lukas Holzer <lukas.holzer@netlify.com>
@netlify-team-account-1
Copy link
Contributor Author

netlify-team-account-1 commented Jan 27, 2022

Something is killing the tests: Command was killed with SIGKILL (Forced termination)

@lukasholzer do you have an idea what's causing this? do we know if it's a problem with the PR, or an external thing?

@lukasholzer
Copy link
Collaborator

lukasholzer commented Jan 27, 2022

Something is killing the tests: Command was killed with SIGKILL (Forced termination)

@lukasholzer do you have an idea what's causing this? do we know if it's a problem with the PR, or an external thing?

My first wild guess would be that it is somehow connected with the PR as the error is somehow related to functions and I've never seen this one before.

So if tests are flaky then they are failing differently (by http endpoint timed out or something like that).

This one seems to be more on the mem crashing side of things on macos :D

CleanShot 2022-01-27 at 10 50 10

while the ubuntu-latest test seems to be something different but related to scheduled functions:

CleanShot 2022-01-27 at 10 53 14

@lukasholzer
Copy link
Collaborator

@netlify-team-account-1 do they pass locally?

@lukasholzer
Copy link
Collaborator

@Skn0tt still not passing? 😬

@Skn0tt
Copy link
Contributor

Skn0tt commented Jan 28, 2022

nope

@lukasholzer lukasholzer merged commit 1c8968d into main Jan 28, 2022
@lukasholzer lukasholzer deleted the scheduled-jobs-endpoint branch January 28, 2022 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants