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 support for Go scheduled functions #4491

Merged
merged 15 commits into from
Mar 29, 2022

Conversation

karagulamos
Copy link
Contributor

@karagulamos karagulamos commented Mar 28, 2022

Summary

The PR is part of an ongoing effort to improve functions support for Go. In this specific case, we sprinkle the CLI with magic dust to enable the detection of scheduled functions in Go and improve the dev experience for anyone wishing to try this out locally.

With this update, users should now see the default message for locally run scheduled functions in their browser

image

You can find relevant code here.

NOTE: next_run is only present in request.Body if the Go function is scheduled.

@karagulamos karagulamos self-assigned this Mar 28, 2022
@github-actions github-actions bot added the type: bug code to address defects in shipped code label Mar 28, 2022
@github-actions
Copy link

github-actions bot commented Mar 28, 2022

📊 Benchmark results

Comparing with 3df8f95

Package size: 380 MB

⬆️ 0.00% increase vs. 3df8f95

^  380 MB  380 MB  380 MB  380 MB  380 MB  380 MB  380 MB  380 MB  380 MB  380 MB  380 MB  380 MB  380 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

@karagulamos karagulamos deleted the fix/detect-go-scheduled-functions branch March 28, 2022 22:24
@karagulamos karagulamos restored the fix/detect-go-scheduled-functions branch March 28, 2022 22:25
@karagulamos karagulamos reopened this Mar 28, 2022
@karagulamos karagulamos added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Mar 28, 2022
@karagulamos karagulamos changed the title Fix lack of local dev support for Go scheduled functions Fix: lack of local dev support for Go scheduled functions Mar 28, 2022
@karagulamos karagulamos changed the title Fix: lack of local dev support for Go scheduled functions feat: add local dev support for Go scheduled functions Mar 28, 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.

Thanks for picking this up!

You're doing a lot of work that is already handled elsewhere.

First of all, you're finding and parsing the config file, which you don't need to. If you look at the FunctionsRegistry class, you'll see that one of the parameters it receives is config. This is the config object fully parsed and normalised, ready for you to use.

Secondly, zip-it-and-ship-it is what should tell us the schedule information about a function, if it exists. It does this by merging the function configuration we pass to it (which we extract from config.functions) with any in-source config declarations, when applicable.

So one of the problems I'm seeing is that we're not passing that configuration object when we call listFunctions here. If you pass a config parameter with the value of this.config.functions, you'll see that any functions with a schedule defined in the config file will come back with the schedule property correctly populated. This handles all the parsing you're replicating in this PR.

Once that's in, I believe the only thing left to do is to pass that schedule property in the NetlifyFunction constructor here, and make NetlifyFunction set that property internally if it's passed in the constructor, as opposed to relying on the build step.

If any of this isn't clear, feel free to drop any questions here or ping me directly and we can pair. 🚀

@karagulamos
Copy link
Contributor Author

karagulamos commented Mar 29, 2022

If any of this isn't clear, feel free to drop any questions here or ping me directly and we can pair. 🚀

Super thanks for the feedback, and I should be able to handle the changes. However, considering this was my point of reference, I believe we no longer need to return the schedule from ZISI with this change and can remove it from the code. Any reason we shouldn't?

@mraerino
Copy link
Contributor

doesn't zisi parse the in-code schedule configuration?

@eduardoboucas
Copy link
Member

Let's think about how the schedule is declared and how it makes its way to us:

  • In the TOML: We have access to this information upfront (i.e. before building a function), because we have an in-memory representation of the config. This is what we need to pass to zip-it-and-ship-it, as mentioned in feat: add local dev support for Go scheduled functions #4491 (review).

  • In the code: We don't have access to this information until we build a function, so we need to get this data from zip-it-and-ship-it. If you remove this, only the TOML declarations will be considered. The data coming from zip-it-and-ship-it for Go functions will be redundant, since it's not possible for the function's build command to generate additional schedule data (because we don't support in-source declarations in Go). However, that's not true for JavaScript/TypeScript, so we need to make sure we consider data coming from both sources (i.e. config and ZISI), so the best way is to always pass the config to ZISI and use the value it returns as the single source of truth, because it will do the job of considering both sources.

Does that make sense?

@karagulamos
Copy link
Contributor Author

Does that make sense?

Figured it out, but this makes a lot of sense, thanks.

@karagulamos
Copy link
Contributor Author

This is resolved.

eduardoboucas
eduardoboucas previously approved these changes Mar 29, 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.

🚀

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.

🚢 🚢 🚢

@karagulamos karagulamos merged commit 1693824 into main Mar 29, 2022
@karagulamos karagulamos deleted the fix/detect-go-scheduled-functions branch March 29, 2022 17:52
eduardoboucas added a commit that referenced this pull request Apr 18, 2022
* fix(deps): update dependency @netlify/plugins-list to ^6.17.0 (#4472)

* fix(deps): update dependency @netlify/plugins-list to ^6.17.0

* chore: update contributors field

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency commander to v9.1.0 (#4466)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>

* chore(main): release 9.13.4 (#4470)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* fix(deps): update dependency netlify to ^11.0.1 (#4473)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency @netlify/build to ^26.5.1 (#4475)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency @netlify/config to ^17.0.19 (#4476)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): bump minimist from 1.2.5 to 1.2.6 in /tests/integration/eleventy-site (#4477)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump minimist from 1.2.5 to 1.2.6 in /site (#4478)

Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: ehmicky <ehmicky@users.noreply.github.com>

* fix(deps): update dependency stripe to v8.211.0 (#4467)

* fix(deps): update dependency stripe to v8.211.0

* style: don't format lock files

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: erezrokah <erezrokah@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore(main): release 9.13.5 (#4474)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* fix(deps): update dependency minimist to v1.2.6 (#4480)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency typescript to v4.6.3 (#4481)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(deps): update rust crate log to 0.4.16 (#4482)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(deps): update dependency stripe to v8.212.0 (#4483)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(deps): update dependency gh-release-fetch to v3.0.2 (#4479)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore(main): release 9.13.6 (#4485)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* chore(deps): update dependency @netlify/eslint-config-node to ^5.1.8 (#4487)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix: polling for API Authentication (#4490)

* feat: add local dev support for Go scheduled functions (#4491)

* fix: detection for Go scheduled functions

* fix: incompatible fs import

* chore: fix conventional message error

* fix: parse schedule from config

* fix: unsupported optional chaining

* fix: broken function test without config

* chore: fix prettier warnings

* fix: additional checks in NetlifyFunction

* feat: assert valid next_run in test

* chore: update names and tests

* feat(dev-graph): populate X-Nf-Graph-Token header (#4493)

* feat(dev-graph): populate X-Nf-Graph-Token header

* chore: update contributors field

* chore: update contributors field

Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore(main): release 9.14.0 (#4492)

* chore(main): release 9.14.0

* chore: update contributors field

* chore: update contributors field

* chore: update contributors field

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com>

* feat: added scheduled functions template for Go (#4495)

* feat: go scheduled functions template

* chore: update contributors field

* chore: placeholder for github handle in go mod

* chore: remove unnecessary makefile

* chore: go version update

Co-authored-by: karagulamos <karagulamos@users.noreply.github.com>

* chore(main): release 9.15.0 (#4496)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* fix(deps): update dependency @netlify/plugins-list to ^6.18.1 (#4494)

* fix(deps): update dependency @netlify/plugins-list to ^6.18.1

* chore: update contributors field

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <renovate[bot]@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* feat: improve functions error messages (#4486)

* feat: implement better error pages for functions in CLI

* chore(main): release 9.16.0 (#4497)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* fix: fallback should there be an error getting the functions error page template (#4499)

* fix: wrap render template in try catch

* chore: include template in files tracked by npm

* chore(main): release 9.16.1 (#4500)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* fix(deps): update dependency cron-parser to v4.3.0 (#4504)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency stripe to v8.215.0 (#4505)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore(main): release 9.16.2 (#4510)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* fix(deps): update dependency @netlify/build to ^26.5.2 (#4512)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency @netlify/config to ^17.0.20 (#4513)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(main): release 9.16.3 (#4514)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* fix(deps): update dependency @netlify/plugins-list to ^6.19.0 (#4516)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency lambda-local to v2.0.2 (#4443)

* fix(deps): update dependency lambda-local to v2.0.2

* chore: update contributors field

* feat: update to correctly mirror synchronous execution (closes #4304)

* chore: update contributors field

* chore: update contributors field

* fix: format

* chore: update contributors field

* chore: update contributors field

* fix: tests

* chore: update contributors field

* chore: update contributors field

* fix: another test

* chore: update contributors field

* fix: another test

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <renovate[bot]@users.noreply.github.com>
Co-authored-by: Netlify Team Account 1 <netlify-team-account-1@users.noreply.github.com>
Co-authored-by: Skn0tt <Skn0tt@users.noreply.github.com>
Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: Simon Knott <info@simonknott.de>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>

* chore(main): release 9.16.4 (#4517)

* chore(main): release 9.16.4

* chore: update contributors field

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com>

* fix(deps): update dependency stripe to v8.216.0 (#4520)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency semver to v7.3.6 (#4518)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency ava to v4.2.0 (#4519)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(deps): update dependency winston to v3.7.2 (#4521)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>

* chore(main): release 9.16.5 (#4525)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>

* chore(deps): update codecov/codecov-action action to v3 (#4522)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(deps): update dependency @netlify/build to ^26.5.3 (#4529)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @netlify/eslint-config-node to v6 (#4501)

* chore(deps): update dependency @netlify/eslint-config-node to v6

* chore: fix eslintrc

* chore: fix linting

* chore: update shrinkwrap file

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: ehmicky <ehmicky@gmail.com>
Co-authored-by: erezrokah <erezrokah@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore(main): release 9.16.6 (#4530)

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* chore: merge main

* chore: remove dependency

* chore: fix linting errors

* chore: fix test

* chore: remove duplicate test

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <renovate[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: ehmicky <ehmicky@users.noreply.github.com>
Co-authored-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
Co-authored-by: Karagulamos <karagulamos@gmail.com>
Co-authored-by: Daniel Woelfel <dwwoelfel@gmail.com>
Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: karagulamos <karagulamos@users.noreply.github.com>
Co-authored-by: Jackie Macharia <jackline.macharia@netlify.com>
Co-authored-by: Netlify Team Account 1 <netlify-team-account-1@users.noreply.github.com>
Co-authored-by: Skn0tt <Skn0tt@users.noreply.github.com>
Co-authored-by: Simon Knott <info@simonknott.de>
Co-authored-by: kodiakhq[bot] <kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: ehmicky <ehmicky@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code 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.

3 participants