{"id":20200999,"url":"https://github.com/openclimatefix/nowcasting_alerts_cron","last_synced_at":"2026-06-20T08:31:32.290Z","repository":{"id":66472886,"uuid":"547246991","full_name":"openclimatefix/nowcasting_alerts_cron","owner":"openclimatefix","description":"Nowcasting Alerts cron Worker","archived":false,"fork":false,"pushed_at":"2023-07-21T14:52:17.000Z","size":113,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T08:45:45.303Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openclimatefix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["openclimatefix"],"patreon":null,"open_collective":"openclimatefix","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2022-10-07T11:20:26.000Z","updated_at":"2023-07-21T14:52:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"a6f8ab4a-3f44-4a8f-9316-42eceaee5d77","html_url":"https://github.com/openclimatefix/nowcasting_alerts_cron","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":"0.30000000000000004","last_synced_commit":"4a712ab52aa7d5e352452e4681a37d57a3001aff"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/openclimatefix/nowcasting_alerts_cron","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openclimatefix%2Fnowcasting_alerts_cron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openclimatefix%2Fnowcasting_alerts_cron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openclimatefix%2Fnowcasting_alerts_cron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openclimatefix%2Fnowcasting_alerts_cron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openclimatefix","download_url":"https://codeload.github.com/openclimatefix/nowcasting_alerts_cron/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openclimatefix%2Fnowcasting_alerts_cron/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34563535,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-20T02:00:06.407Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T04:46:27.489Z","updated_at":"2026-06-20T08:31:32.273Z","avatar_url":"https://github.com/openclimatefix.png","language":"TypeScript","funding_links":["https://github.com/sponsors/openclimatefix","https://opencollective.com/openclimatefix"],"categories":[],"sub_categories":[],"readme":"# Nowcasting Alerts Cron Workers\n\nThe repo [nowcasting_alerts](https://github.com/openclimatefix/nowcasting_alerts) contains the main Remix application for managing alerts. But Cloudflare Pages does not support ScheduledEvents (cron). So this separate repo houses cron worker functions.\nLearn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/\n\nWe use [npm workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces) (npm\nversion 7+) to manage multiple `package.json` files (a separate package is\nrequired for each Cloudflare Worker).\n\n# Workers\n\n## deviation\n\nChecks for a deviation in the PV_Live and Nowcasting forecasts, and sends a webhook to all configured alerts if there is.\n\n## daily_max\n\nRuns every morning at 7am UTC and finds the highest forecast for the day, and sends it as a webhook to all configured alerts.\n\n# Running locally\n\n```\nnpm i\n```\n\n1. For each Cloudflare Worker (directories in root, e.g. `daily_max`), make a copy of `wrangler.toml.example` and rename\n   it to `wrangler.toml`.\n2. You'll need to grab the Auth0 `CLIENT_ID` and `CLIENT_SECRET` from the\n   [Auth0 dashboard](https://manage.auth0.com/dashboard/eu/nowcasting-pro/applications) in the \"Alerts App\"\n   Machine-to-Machine application. and paste them into the `wrangler.toml` file under `[vars]` for each Worker.\n3. The `wrangler.toml` file for each Worker also needs the `kv_namespaces` section filled in with the KV namespace IDs\n   for the `nowcasting-alerts-ALERTS` and `nowcasting-alerts-LOG` KV namespaces. If you're running locally, you'll also\n   need to add a \"preview_id\" for each KV namespace, these can also be found using the CF Dashboard or the CLI.\n   You can find these in the Cloudflare dashboard main nav Workers \u003e KV.\n4. Run worker locally **_either_** with:\n```\nnpm run dev --workspace=[Cloudflare Worker folder name]\n```\n\n5. Run `curl \"http://localhost:8787/cdn-cgi/mf/scheduled\"` to trigger the scheduled event\n   Go back to the console to see what your worker has logged\n\n_**or**_\n\nSometimes the preview KV doesn't seem to sync properly, so you can run the worker locally with:\n```\nnpx wrangler dev --test-scheduled\n```\n\nSimilarly, you can then ping the worker with:\n```\ncurl \"http://localhost:8787/__scheduled\"\n```\n\u003e N.B. Wrangler can pick up the KV variables from the `wrangler.toml` file, but it doesn't seem to pick up variables\n\u003e from an .env file, so they have to be in the `wrangler.toml` file. \n\u003e \n\u003e If you want to use an `.env` file, you can put the Auth0 variables in there, but you'll need to add the KV variables \n\u003e to the `wrangler.toml` file still.\n\n\n# Production\n\n## Setup KV for production\n\nData for this app is stored using Cloudflare key-value storage\n(when setting up the main repo you will have already done: \n- Create KV namespaces: `nowcasting-alerts-ALERTS`, `nowcasting-alerts-LOG`)\n- Copy wrangler.toml.example to wrangler.toml\nGo to Cloudflare dashboard main nav Workers \u003e KV and copy the IDs for nowcasting-alerts-ALERTS, \nnowcasting-alerts-LOG then paste them into the kv_namespaces in wrangler.toml\n\nIf you add a new worker, ensure you create a preview KV namespace for both `ALERTS` and `LOG`:\n```bash\nnpx wrangler kv:namespace create \"LOG\" --preview\nnpx wrangler kv:namespace create \"ALERTS\" --preview\nnpx wrangler kv:namespace create \"STORAGE\" --preview\n```\nand add the IDs to the `wrangler.toml` file for the new worker under \"preview_id\".\nYou can find these in the Cloudflare dashboard main nav Workers \u003e KV, or manage from the CLI:\n```bash\n# List all KV namespaces\nnpx wrangler kv:namespace list\n\n# List all KV keys in a specific namespace that is bound to the current Worker (if in that directory)\nnpx wrangler kv:key list --binding=ALERTS [--preview]\n\n# Get the value of a specific KV key in a namespace that is bound to the current Worker (if in that directory)\nnpx wrangler kv:key get --binding=ALERTS [--preview] \u003ckey_id\u003e\n\n# Put a value into a specific KV key in a namespace that is bound to the current Worker (if in that directory)\nnpx wrangler kv:key put --binding=ALERTS [--preview] \u003ckey_id\u003e [value]\n```\n\n## Deployment\n\n- Ensure the Auth0 environment variables are set in the Cloudflare dashboard\n  Workers \u003e [worker-name] \u003e Settings \u003e Environment Variables and are *encrypted*. These should be set already.\n- Publish all the Workers to Cloudflare:\n\n```\nnpm run publish --workspaces\n```\n\n- Or deploy to production an individual Worker:\n\n```\nnpm run deploy --workspace=[Cloudflare Worker name]\n```\n\n# Limitations\n\nThere are\n[some permission issues](https://github.com/cloudflare/wrangler/issues/240) when\ninstalling `wrangler` as a dependency in an npm workspace. As a workaround, I've\nmade `wrangler` a dependency in the top-level `package.json` for the overall\nmonorepo, and omitted `wrangler` from the dependencies for each workspace. That\nmeans that **the npm scripts in each workspace depend on `wrangler` being\ninstalled outside of the workspace**. So if you wanted to pull a workspace out\nof the monorepo and run the workspace on its own, you must re-add `wrangler` to\nthe workspace dependencies first.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenclimatefix%2Fnowcasting_alerts_cron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenclimatefix%2Fnowcasting_alerts_cron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenclimatefix%2Fnowcasting_alerts_cron/lists"}