Skip to content

Commit

Permalink
run scheduled from setup (for improved logging)
Browse files Browse the repository at this point in the history
  • Loading branch information
avirut committed Jul 16, 2023
1 parent e90dac7 commit 366a1aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
python /app/src/setup.py && python /app/src/run_scheduled.py
python /app/src/setup.py
34 changes: 20 additions & 14 deletions src/run_scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@
if not os.environ.get("IS_DOCKER", False):
dotenv.load_dotenv()

schedule.every(1).week.do(
run_update, days_to_fetch=int(os.environ.get("WEEKLY_PULL_PAST_DAYS"))
)
schedule.every(1).day.do(
run_update, days_to_fetch=int(os.environ.get("DAILY_PULL_PAST_DAYS"))
)
schedule.every(1).hour.do(
run_update, days_to_fetch=int(os.environ.get("HOURLY_PULL_PAST_DAYS"))
)

print("Entering scheduled update loop.")
while True:
schedule.run_pending()
time.sleep(10)

def run_scheduled():
schedule.every(1).week.do(
run_update, days_to_fetch=int(os.environ.get("WEEKLY_PULL_PAST_DAYS"))
)
schedule.every(1).day.do(
run_update, days_to_fetch=int(os.environ.get("DAILY_PULL_PAST_DAYS"))
)
schedule.every(1).hour.do(
run_update, days_to_fetch=int(os.environ.get("HOURLY_PULL_PAST_DAYS"))
)

print("Entering scheduled update loop.")
while True:
schedule.run_pending()
time.sleep(10)


if __name__ == "__main__":
run_scheduled()
5 changes: 5 additions & 0 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gspread
import requests

from run_scheduled import run_scheduled
from update import run_update

if not os.environ.get("IS_DOCKER", False):
Expand Down Expand Up @@ -88,3 +89,7 @@
run_update(days_to_fetch=int(os.environ.get("SETUP_PULL_PAST_DAYS")))

print("Setup complete!")

if os.environ.get("IS_DOCKER", False):
print("Initializing scheduled updates...")
run_scheduled()

0 comments on commit 366a1aa

Please sign in to comment.