visch
03/02/2023, 7:17 PMclean_up
message re https://sdk.meltano.com/en/latest/classes/singer_sdk.Sink.html#singer_sdk.Sink.clean_up
With taps we don't have the equivalent for Streams or taps, so what if we want to do something like a connection to a DB and then close the connection to the DB. Today even with the SQL Alchemy jobs we're making a seperate connection for each stream.
Maybe I"m wrong and someone can prove it to me?alexander_butler
03/02/2023, 8:03 PMTap
class and use atexit
stdlib module to register clean ups. 🤷visch
03/02/2023, 8:30 PMedgar_ramirez_mondragon
03/02/2023, 9:05 PMvisch
03/02/2023, 9:36 PMNote: The functions registered via this module are not called when the program is killed by a signal not handled by Python, when a Python fatal internal error is detected, or whenInterestingis called.os._exit()
visch
03/02/2023, 9:38 PMsignal
still interestingalexander_butler
03/02/2023, 9:40 PMatexit
is pretty common to use in this situation where you want a clean up script in most situations. Going deeper into signal handling and trying to "overpower" the user or OS to run your cleanup even in the event of fatal failure is unnecessary or unexpected in most cases (if it even works)?alexander_butler
03/02/2023, 9:42 PMalexander_butler
03/02/2023, 9:43 PMsignal
, I just like the simplicity of atexit
the times I've needed to reach for itvisch
03/02/2023, 9:54 PMvisch
03/02/2023, 9:56 PMimport signal
import atexit
def clean_up():
print("cleaning up!")
signal.register(signal.SIGTERM, clean_up)
signal.register(signal.SIGINT, clean_up)
atexit.register(clean_up)
Theoretically would do both I think 🤷visch
03/02/2023, 9:56 PMalexander_butler
03/02/2023, 9:59 PMiirc meltano sends a sigterm to the tap on a target failure. So you'd probably want both hereAh I see. I am imaging the experience for people using the tap/target in general and running
kill
in their terminal in a frenzy to stop the accidental beast they've released on their prod system only to be met with a forced clean up LOL
def catch_sig():
exit(1)
def clean_up():
print("cleaning up!")
signal.register(signal.SIGTERM, catch_sig)
signal.register(signal.SIGINT, catch_sig)
atexit.register(clean_up)