Skip to content

Commit

Permalink
fix(itau): schedule running every 3 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasrcezimbra committed Jan 21, 2024
1 parent e62e9d7 commit 5b73652
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cronjobs/gastos/itau/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from decouple import config
from loguru import logger
from pyitau import Itau
from schedule import every, repeat, run_pending
from schedule import every, idle_seconds, repeat, run_all, run_pending

from cronjobs.gastos import sheet
from cronjobs.gastos.itau import checking_account, credit_card


def main(date_):
@repeat(every(3).hours)
def main(date_=None):
date_ = date_ or datetime.now().date() - timedelta(days=2)
logger.info(f"Running Itaú {date_}")
itau = Itau(
agency=config("ITAU_AGENCY"),
Expand Down Expand Up @@ -48,13 +50,14 @@ def main(date_):


@app.command()
@repeat(every(3).hours)
def schedule():
main(datetime.now().date() - timedelta(days=2))

run_all()
while True:
n = idle_seconds()
if n > 0:
logger.info(f"Sleeping for {n} seconds")
time.sleep(n)
run_pending()
time.sleep(60 * 60)


@app.command()
Expand Down

0 comments on commit 5b73652

Please sign in to comment.