Skip to content

Commit

Permalink
Merge pull request hackforla#1023 from hackforla/mattyweb/issue935
Browse files Browse the repository at this point in the history
Create job to recycle dashboards every night
  • Loading branch information
mattyweb authored Mar 12, 2021
2 parents 2d56b08 + 5c6b1e6 commit 496793e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/prefect/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ reset_db = false
temp_folder = ""
# set to local API instance or override with PREFECT__API_URL
api_url = "http://localhost:5000"
# set to local API instance or override with PREFECT__API_URL
report_server_url = "https://dash-reporting.tofn9kh9mlm7g.us-east-1.cs.amazonlightsail.com"
# whether the data update is being run in a testing, development or production environment
stage = "Testing"
# whether to vacuum database and reset stats after load
Expand Down
11 changes: 8 additions & 3 deletions server/prefect/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@
complete = postgres.complete_load()

# clear the API cache
cache = cache.clear_cache()
clear = cache.clear_cache()

# clear the API cache
reload = cache.reload_reports()

# make sure prep runs before load
flow.add_edge(upstream_task=prep, downstream_task=load)
# make sure load runs before complete
flow.add_edge(upstream_task=load, downstream_task=complete)
# make sure load runs before complete
flow.add_edge(upstream_task=complete, downstream_task=cache)
# make sure complete runs before cache is cleared
flow.add_edge(upstream_task=complete, downstream_task=clear)
# make sure load runs before complete
flow.add_edge(upstream_task=clear, downstream_task=reload)

if __name__ == "__main__":
logger = prefect.context.get("logger")
Expand Down
17 changes: 17 additions & 0 deletions server/prefect/tasks/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from prefect.utilities.tasks import task

CACHE_PATH = "/status/reset-cache"
RELOAD_PATH = "/reload"


@task
Expand All @@ -20,3 +21,19 @@ def clear_cache():
logger.info(f"Cache clearing successful: {reset_path}")
else:
logger.info("Cache clearing failed")


@task
def reload_reports():
"""
clears the server cache once new data is done loading
"""
logger = prefect.context.get("logger")
report_server_url = prefect.config.report_server_url
reload_path = f"{report_server_url}{RELOAD_PATH}"
response = requests.get(reload_path)

if response.status_code == 200:
logger.info(f"Report reloading successful: {reload_path}")
else:
logger.info("Report reloading failed")

0 comments on commit 496793e

Please sign in to comment.