https://prefect.io logo
#prefect-community
Title
# prefect-community
j

Jared Robbins

08/18/2022, 8:19 PM
A function to check if a block already exists would be helpful
👍 1
a

alex

08/18/2022, 8:45 PM
Hey @Jared Robbins, thanks for the suggestion! Could you provide an example of when such a function would be helpful?
j

Jared Robbins

08/18/2022, 9:07 PM
Conditionally running a task based on last time it was run. There is no last time if it is the first time.
a

alex

08/18/2022, 10:29 PM
Gotcha, so in that case it sounds like you would use a
DateTime
block to hold the last run time and that value would be saved on each run. To handle the case where a block document doesn’t exist, you can run
DateTime.load("my-block-name")
in a try clause and catch the
ValueError
that is thrown if a block document with that name doesn’t exist. You then would be able to create the block in the except clause.
j

Jared Robbins

08/18/2022, 10:32 PM
Hm, i’ll try that again tomorrow. For some reason it wasn’t catching the error.
Man… it was because I was creating a new block using String(‘’) in the except block. Forgot to specify value= On the bright side, the whole thing is working great now :)
6 Views