liveblog icon indicating copy to clipboard operation
liveblog copied to clipboard

[LBSD-2832] - Create Go pricing plan notification for bandwidth

Open BrianMwangi21 opened this issue 6 months ago • 0 comments

Purpose

This PR introduces an implementation to fetch bandwidth usage for Go pricing plan and notify the user on the client side.

What has changed

  • Added a new Bandwidth resource and service to store the bandwidth of the client.
  • Added a new task to make the API call to fetch bandwidth usage from Cloudflare and scheduled it for midnight.
  • Added endpoint to fetch bandwidth usage on client side and notify the user when close to upper bandwidth limit

Steps to test

  1. Checkout to this branch and set needed env variables for the server, then run Liveblog. Ensure the subscription level is 'liveblog-go'.
SUBSCRIPTION_LEVEL='liveblog-go'
CLOUDFLARE_URL=''
CLOUDFLARE_AUTH=''
CLOUDFLARE_ZONE_TAG=''
  1. Under the server directory, initialize data to create new bandwidth collection
$ python3 manage.py app:initialize_data;
  1. For easier testing, you can change the schedule of the task to run every two minutes under settings.py
    "bandwidth:update": {
        "task": "liveblog.bandwidth.tasks.fetch_bandwidth_usage",
        # "schedule": crontab(minute=0, hour=0),  # every midnight
        "schedule": crontab(minute="*/2"),  # every 2 minutes
    },

  1. Observe the logs to see the task being called and running.
  2. After a while, log in on the client side and if the bandwidth used is greater than 75%, it should show a warning notification. You can reduce this value in client/app/scripts/liveblog-bloglist/controllers/blog-list.js for easier testing.

Resolves: LBSD-2832

BrianMwangi21 avatar Aug 09 '24 07:08 BrianMwangi21