https://prefect.io logo
Title
f

FuETL

11/21/2022, 11:05 AM
Hey guys there a reason for signals (
FAIL
,
PrefectStateSignal
,
PrefectSignal
) inherit from
BaseException
instead of
Exception
?
Sorry to bump it, is because i faced some issues using:
try:
    ...
except Exception as err:
    pass
and raising fail signal it was not being catched.
a

Anna Geller

11/21/2022, 10:38 PM
what problem are you trying to solve?
you don't need to use try/except necessarily when you use Prefect, signals were needed in v1 to do things like skipping some tasks, raising a retry signal to cause a rerun of something or pausing the execution in some other way. once you migrate to v2, you can use native python so signals won't be required
internally in v1 we are using those signals to bypass all other exception handling since they are signals not actual errors
but those shouldn’t be caught unless you want to use them e.g. raise SKIP or RETRY signal
f

FuETL

11/22/2022, 12:54 PM
@Anna Geller Thanks for the answer (i using v1), basically my usage is i have a task lets say with 3 retries. If is the last retry (before raise FAIL signal again), i need to send a e-mail to notify the interested parties, so inside my task i raise SIGNAL and catch them in the
except
statement, that was the cause of this question.
and of course if is last time i send the email and then raise the signal 😄
import pendulum
from prefect.engine.signals import RETRY
import awswrangler as wr

def check_if_file_arrived_in_s3():
    return wr.s3.does_object_exist("<s3://bucket/example_file.csv>")

@task
def s3_sensor(**kwargs):
    bool_s3_object_arrived = check_if_file_arrived_in_s3()
    if bool_s3_object_arrived is False:
        raise RETRY(
            "File not available yet, retrying in 20 seconds.",
            start_time=pendulum.now().add(seconds=20),
        )
❤️ 1