Hi folks! I'm wondering if there's a way to code a...
# ask-community
j
Hi folks! I'm wondering if there's a way to code a Task that would be mapped, but initialized only once. I want to map a rollbar task onto a result (list) from a previous task, but ideally I would like to call the rollbar.init() only once. Anyone know how I could do that?
k
Hi @Jérémy Trudel ! Not entirely what you’re trying to do, but are you aware of Unmapped inputs ?
j
Yes! I'm using an api (rollbar) to send message. One message for each item of a previous task. Normally you initialize rollbar once with an access token within a script
Copy code
rollbar.init(access_token)
I wanted to know if it was possible to have an object that would be mapped (so the run method would be called multiple times), but the
Copy code
__init__()
would be called only once. Does that make sense? I'm trying to avoid having a separate task for initialization, so that the mapped task could be easily reusable in different scripts without always setting up first an initialization unstream task. I hope that makes sense
k
I think I understand. I think the only way this can be done is to split it in different tasks, and pass the rollbar into the mapped call as an
unmapped
input. The issue is that I think the rollbar object may be unserializable, and task outputs need to be serializable to be distributable to
DaskExecutor
workers.
j
I see, thank you. I'll try that and if not I'll just make it two separate tasks
👍 1