ONSdigital / dp-data-pipelines

Pipeline specific python scripts and tooling for automated website data ingress.
MIT License
1 stars 0 forks source link

decorator - enrich notifications #63

Closed mikeAdamss closed 5 months ago

mikeAdamss commented 5 months ago

What is this

We have the ability to send basic pre canned message templates, see here.

This task it to write a decorator such that said messages are enriched with "online only" contextual information.

initial use case - including the url to a glue job in any outgoing messages sert from a glue job.

What to do

Here is an example decorator

def enrich_online(message_creating_function):
    def wrapper(*args):
        msg: str = message_creating_function(*args)

        # Do something here to enrich "msg" which will
        # have added what we want to it.

        # For now - see the "what does the decorator need to do"
        # section down below.

        return msg
    return wrapper

which you would use like so

@enrich_online
def unexpected_error(msg: str, error: Exception) -> str:
    # the rest of this function, please see
    # https://github.com/ONSdigital/dp-data-pipelines/blob/0682f4e8ca72fc5309bbd032c56a85acceeedb92/dpypelines/pipeline/shared/message.py#L13C1-L13C57

...what does the decorator need to do...

This task is not to work out the url we want from glue (that's a different task). What we want here is:

Important - dont get tangled on the logic of this. In essence all we want right now is a decorator that will sit on top of a function that returns a string - and add something to the end of the string being returned, that's it.

Acceptance Criteria

mikeAdamss commented 5 months ago

done