Skip to content

Commit

Permalink
Merge pull request #556 from OpenUpSA/feature/api-bill-tracker-update…
Browse files Browse the repository at this point in the history
…-method

Feature/api bill tracker update method
  • Loading branch information
paulmwatson authored Jul 30, 2024
2 parents a1c46f9 + 97e4c28 commit f408952
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
14 changes: 11 additions & 3 deletions pmg/api/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sqlalchemy import desc
from sqlalchemy.orm import defer, noload
from sqlalchemy.sql.expression import nullslast
from pmg.bill_tracker import produce_bill_tracker_json

from pmg import cache, cache_key, should_skip_cache
from pmg.models import (
Expand Down Expand Up @@ -251,11 +252,18 @@ def daily_schedules(id=None):
return api_list_items(DailySchedule.list(), DailyScheduleSchema)


@api.route("/bill-tracker")
@api.route("/bill-tracker/")
def bill_tracker():
# Return background-worker produced static JSON file from pmg/static/bill-tracker.json
try:
with open("pmg/static/bill-tracker.json", "r") as f:
return f.read()
return f.read()
except FileNotFoundError:
return abort(404)
return abort(500)


@api.route("/bill-tracker/update/")
def bill_tracker_update():
# Update the bill-tracker.json file
produce_bill_tracker_json()
return "/v2/bill-tracker JSON updated"
17 changes: 0 additions & 17 deletions pmg/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ def sync_soundcloud():
SoundcloudTrack.sync()


def produce_bill_tracker_json():
from pmg import app
from pmg.bill_tracker import produce_bill_tracker_json

with app.app_context():
produce_bill_tracker_json()


def schedule(scheduler):
jobs = [
# Schedule background task for sending saved search alerts every
Expand All @@ -45,15 +37,6 @@ def schedule(scheduler):
coalesce=True,
hour=3,
),
scheduler.add_job(
"pmg.tasks:produce_bill_tracker_json",
"cron",
id="produce-bill-tracker-json",
replace_existing=True,
coalesce=True,
hour=1,
next_run_time=datetime.datetime.now(),
),
scheduler.add_job(
sync_soundcloud,
"cron",
Expand Down

0 comments on commit f408952

Please sign in to comment.