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 forecast updater for climate forecast refresh #327

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

OchiengPaul442
Copy link
Collaborator

@OchiengPaul442 OchiengPaul442 commented Sep 20, 2024

Description

This PR implements the following changes as part of the proof of concept for automating climate forecast refresh every hour:

Created forecastUpdater.ts:

(created this within the E:\intern\picsa-apps\apps\picsa-server\supabase\functions\climate-refresh for now)

  • this edge function pulls climate forecast data dynamically based on the provided country code and stores it in Supabase.
  • fetches forecasts from the Climate API and stores the formatted data in Supabase’s climate_forecasts table.
  • supports dynamic country_code via URL query parameters.
  • uses the upsert method to insert or update forecast data into the database to avoid duplication.
  • handles and logs errors during both the forecast fetching and storing processes.

Hourly cron trigger

  • needs testing to check the storage of the fetched forecast data before deployment to supabase because it failed on testing this out locally though the function can handle both fetching and storage of the data to supabase.

Discussion

This PR is solving this issue: #303

Testing

to test this out locally, have deno installed and run the following command:
deno run --allow-net --allow-env forecastUpdater.ts

  • when testing locally had to delete the deno.lock file to avoid the hash mismatch errors
  • successfully fetched the document/forecast data but could not test the storage locally due to Error: SUPABASE_URL is required.

Future Enhancements

An alternative approach that was found could involve utilizing Supabase's Remote Procedure Call (RPC) to run a stored procedure that fetches and stores the forecast data. This would need setting up an RPC script in Supabase though.

some blockers faced

  • When attempting to reuse the existing logic from climate-api.mapping.ts for fetching and storing forecast data, the Deno environment led to several type errors. These errors were due to the lack of alias support in Deno, which would have required significant code refactoring to resolve.

Preview

Link to app preview if relevant

Screenshots / Videos

image

@OchiengPaul442 OchiengPaul442 self-assigned this Sep 20, 2024
@github-actions github-actions bot added the App: Dashboard Updates related to Dashboard app label Sep 20, 2024
@OchiengPaul442 OchiengPaul442 changed the title Feat Climate forecast refresh feat: add forecast updater for climate forecast refresh Sep 20, 2024
@github-actions github-actions bot added feature and removed feature labels Sep 20, 2024
Copy link

nx-cloud bot commented Sep 20, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 6e0ea62. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@github-actions github-actions bot added feature and removed feature labels Sep 20, 2024
@github-actions github-actions bot added feature and removed feature labels Sep 20, 2024
@github-actions github-actions bot added feature and removed feature labels Sep 20, 2024
@OchiengPaul442 OchiengPaul442 linked an issue Sep 20, 2024 that may be closed by this pull request
@github-actions github-actions bot added feature and removed feature labels Sep 20, 2024
@github-actions github-actions bot added feature and removed feature labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App: Dashboard Updates related to Dashboard app feature ready for review
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

feat(server): automate forecast refresh
1 participant