Hi everyone. I'm currently playing around with the...
# singer-target-development
h
Hi everyone. I'm currently playing around with the sdk to develop a custom target so I can learn. Is there any way to know when the stream ends in
sinks.py
? so for each record
process_record
is called and only after processing the last record I'd like to call another function
do_cleanup()
that does some work
d
My understanding of the SDK is somewhat limited. But I recently implemented a target using
BulkSink
. From my understanding as defined in the base sink class. Sinks are partitioned by stream name, meaning you would have new objects being instantiated/cleaned once per stream. It looks like there is a variable _`records_to_drain`_ In the base class as well, but I dont have any exp using it in my target.
When implementing your target, I would assume there really is no reason to know where the stream ends. But I might be misunderstanding your question.
a
I added a cleanup hook to the SDK for that reason. Its sink specific and runs at end of pipe / end of input. https://github.com/meltano/sdk/blob/main/singer_sdk/sinks/core.py#L443
h
thanks @alexander_butler! this has been the way I was experimenting with, however I couldn't get it to work. Don't we just need to override
def clean_up
in the sink class and it should be called at the end of each stream? I've read the source code and your PR, but the function does not get called
I know it's impossible for you to repro without a concrete example, I just wanted to ask if I'm missing anything obvious
@dt_mirizzi - thanks. the reason I need to know if the stream ends or not is because there are remote connections that I need to manually close after I'm done sending data. I cannot do that without knowing if the stream ended or not
oh my 😞 meltano cookiecutter template was using sdk 0.5 instead of 0.16 😭