Corris Randall

08/05/2022, 8:41 PM
So since 2.0 was released, I thought I’d play around with it a little more seriously…. first question… Can we write our own NotificationBlock implementations? or, are there any instructions or examples? I made a test one called “my-email”, but I get an error “No class found for dispatch key ‘my-email’ in registry for type ‘Block’.” when it triggers ( I was able to add the block, and add a notification using that block, but when it fires, that’s the error I get. I register the block with prefect block register --file then add [“notify”] to the block_document row manually in the db.
from typing import Optional
from prefect.utilities.asyncutils import sync_compatible
from prefect.blocks.notifications import NotificationBlock

class MyEmail(NotificationBlock):

    _block_type_name = "My Email"
    _block_type_slug = "my-email"
    _block_schema_capabilities = ["notify"]
    async def notify(self,body: str,subject: Optional[str] = None):
        await print( f"In my email notify subject: {subject}\nbody: {body}" )

Anna Geller

08/05/2022, 11:24 PM
No examples yet, but as long as you save and register a block, it should work If it doesn't, I believe the easiest way to troubleshoot would be if you would open a GitHub issue

Corris Randall

08/05/2022, 11:29 PM
Thanks Anna. I was able to get it to work by putting my class right in prefect/blocks/notifications right under the slack one. But registering it using prefect block register doesn't seem to work. I'll try again with a completely fresh install with sqlite and if it still doesn't work I'll open a GitHub issue. My ‘await’ is wrong there too, but it still doesn't like the manual registration.


08/06/2022, 12:31 AM
@Corris Randall you definitely SHOULD be able to write, register, and use completely custom notification blocks so definitely let us know if you hit any friction. Admittedly our focus has been on building the first generation of blocks with our partners at this time, but the same API we use is intended for users to use as well! We’ll have more recipes soon as the registration routes mature.
👍 2
:thank-you: 1

Corris Randall

08/06/2022, 12:43 AM
Makes sense. it’ll be a while before I can rewrite my flows to 2.0 anyways, but I wanted to see how the translation might be based on how we’re using it. 2.0 looks really promising. issue submitted :)
👍 2
:thank-you: 2