Skip to content

Commit

Permalink
Merge pull request bukosabino#88 from bukosabino/develop-schedule-han…
Browse files Browse the repository at this point in the history
…dle-exception

Handling exceptions for scheduled jobs
  • Loading branch information
bukosabino authored May 22, 2024
2 parents 5c4fbfe + 5102130 commit 5a380ea
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/etls/boa/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

from src.email.send_email import send_email
from src.etls.boa.scrapper import BOAScrapper
from src.etls.utils import catch_exceptions
from src.etls.boa.defs import COLLECTION_NAME
from src.etls.common.etl import ETL
from src.initialize import initialize_app

app = typer.Typer()

@app.command()
@catch_exceptions(cancel_on_failure=True)
def today(init_objects=None):
if init_objects is None:
init_objects = initialize_app()
Expand Down
2 changes: 2 additions & 0 deletions src/etls/bocm/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from src.email.send_email import send_email
from src.etls.bocm.scrapper import BOCMScrapper
from src.etls.common.etl import ETL
from src.etls.utils import catch_exceptions
from src.etls.bocm.defs import COLLECTION_NAME
from src.initialize import initialize_app

Expand All @@ -13,6 +14,7 @@


@app.command()
@catch_exceptions(cancel_on_failure=True)
def today(init_objects=None):
if init_objects is None:
init_objects = initialize_app()
Expand Down
2 changes: 2 additions & 0 deletions src/etls/boe/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from src.email.send_email import send_email
from src.etls.boe.scrapper import BOEScrapper
from src.etls.common.etl import ETL
from src.etls.utils import catch_exceptions
from src.etls.boe.defs import COLLECTION_NAME
from src.initialize import initialize_app

Expand All @@ -13,6 +14,7 @@


@app.command()
@catch_exceptions(cancel_on_failure=True)
def today(init_objects=None):
if init_objects is None:
init_objects = initialize_app()
Expand Down
2 changes: 2 additions & 0 deletions src/etls/boja/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

from src.email.send_email import send_email
from src.etls.boja.scrapper import BOJAScrapper
from src.etls.utils import catch_exceptions
from src.etls.boja.defs import COLLECTION_NAME
from src.etls.common.etl import ETL
from src.initialize import initialize_app

app = typer.Typer()

@app.command()
@catch_exceptions(cancel_on_failure=True)
def today(init_objects=None):
if init_objects is None:
init_objects = initialize_app()
Expand Down
2 changes: 2 additions & 0 deletions src/etls/bopv/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
from src.email.send_email import send_email
from src.etls.bopv.scrapper import BOPVScrapper
from src.etls.bopv.defs import COLLECTION_NAME
from src.etls.utils import catch_exceptions
from src.etls.common.etl import ETL
from src.initialize import initialize_app

app = typer.Typer()

@app.command()
@catch_exceptions(cancel_on_failure=True)
def today(init_objects=None):
if init_objects is None:
init_objects = initialize_app()
Expand Down
2 changes: 2 additions & 0 deletions src/etls/bopz/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from src.email.send_email import send_email
from src.etls.bopz.scrapper import BOPZScrapper
from src.etls.bopz.defs import COLLECTION_NAME
from src.etls.utils import catch_exceptions
from src.etls.common.etl import ETL
from src.initialize import initialize_app

Expand All @@ -13,6 +14,7 @@


@app.command()
@catch_exceptions(cancel_on_failure=True)
def today(init_objects=None):
if init_objects is None:
init_objects = initialize_app()
Expand Down
18 changes: 18 additions & 0 deletions src/etls/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import functools

import schedule


def catch_exceptions(cancel_on_failure=False):
def catch_exceptions_decorator(job_func):
@functools.wraps(job_func)
def wrapper(*args, **kwargs):
try:
return job_func(*args, **kwargs)
except:
import traceback
print(traceback.format_exc())
if cancel_on_failure:
return schedule.CancelJob
return wrapper
return catch_exceptions_decorator

0 comments on commit 5a380ea

Please sign in to comment.