ryanwhowe / statusboard

This is a personal status board project that is not really written to be shared
1 stars 0 forks source link

Update Weather Api's caching #70

Closed ryanwhowe closed 3 years ago

ryanwhowe commented 4 years ago

Is your feature request related to a problem? Please describe. The basic problem is that we are running out of weather api calls when performing testing and development on the project. The current Accuweather api limits the free api calls to 50 per day. Whenever developing or testing there are 2 calls that are made, the first is to the location service to get a location id for the town, then the second is to use that location id to request the weather. Between testing, development and production this call limit is quickly depleted on any day that development is being performed.

Some call usage breakdowns Calls Used Event
6 Each Deployment, 3 for test, 3 for cache refresh
3 Each PhpUnit run
3 Each required cache refresh
3 Each manual cache refresh

using the numbers above, if a development work is done, we use 3 calls to boot the local dev environment, 3 calls to run tests (assume only on run needed), once changes are made, a deployment will consume 6 additional calls. A single development task minimally will consume 12/50 (24%) of the available api calls. The minimal api calls that the statusboard requires to function throughout a day are 1 (daily location update) + 2 per hour forecast update or 21/50 (42%) of the available calls per 10 hour day. Leaving 29 api calls before there is no returned data.

Describe the solution you'd like The primary issue is to not run out of API calls throughout the day without having to limit any activity.

Describe alternatives you've considered With the Environment checks being made available in PR #69 there is the possibility to utilize a Guzzle Mock when in a testing environment which would reduce the utilization for a testing pipeline and local phpunit tests.

If possible use a different test structure to validate the api token vs validating the response of the internal API.

Moving caching outside the application could reduce the required api calls per deployment.

Getting a second api key would double the call volume, but is against the agreement.

Additional context Accuweather Api Guide Accuweather Api Best Practices

ryanwhowe commented 4 years ago

Updates on this issue:

  1. 72 updated the api to use mock data when the environment is set to test. This also updated the phpunit tests to set the environment to test before issuing requests to the Api WebTestCases.

  2. 73 took this further and has all Api calls that utilize 3rd party apis utilize mock data when in test. It also updated the controllers to not need the parameters file when in testing, the test user password has been moved to the dist parameters file for testing usage.

  3. 74 Also has been created to add more visibility into the remaining request limit which should help the understanding of where we sit at any given time in our limit.

The results should be that 1/2 the calls required to perform a deployment have been removed, and ALL the calls that would have been required to run a unit test and CI run have been removed.

I will leave this ticket open to see if we still want to explore more options, I would be open to adding a second weather provider to allow for the weather API to be configurable or to have a fall over data source for when we run out of available requests to Accuweather, but that should be in a separate issue.

ryanwhowe commented 3 years ago

This appears to be resolved, it has been some time since I have run out of requests regardless of the work that was being performed