M-Welsch / base-bcu

Backup Server's (BaSe) backup control unit (bcu). Python software that controls the high level functionality of BaSe
1 stars 0 forks source link

Wait for mailer to finish before shutdown #42

Closed M-Welsch closed 2 years ago

M-Welsch commented 2 years ago
INFO: BaSe.base.base_application: Exiting BaSe Application, about to shut down
shutdown command overridden. Staying awake.
CRITICAL: BaSe.base.common.mailer: Error occurred during sending summary: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials y9-20020a170906070900b006feb3d65337sm265182ejb.102 - gsmtp')

Shutdown is issued before Mailer is finished.

M-Welsch commented 2 years ago

issue still present:

2596879 30.06.2022 06:15:32 INFO: BaSe.base.hardware.power: Unpowering HDD
2596880 30.06.2022 06:15:32 DEBUG: BaSe.base.hardware.mechanics: Already undocked
2596881 30.06.2022 06:15:32 INFO: BaSe.base.hardware.hardware: Preparing SBU for shutdown. Wake up in 3867s. Transferring timestamp: 30.06.2022 07:20
2596882 30.06.2022 06:15:33 INFO: BaSe.base.hardware.sbu.sbu: Command: message_code = BU, payload = 3867
2596883 30.06.2022 06:15:34 INFO: BaSe.base.base_application: Exiting BaSe Application, about to shut down
2596884 30.06.2022 06:15:34 DEBUG: BaSe.base.common.config.bound: reloading config: /home/base/base-bcu/base/config/notification.json
M-Welsch commented 2 years ago

inexplicable. Docu (https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.sendmail) says, the send_message function returns normally when at least one recipient has not refused to accept the message. I understand this as statement that the function call is blocking.

This method will return normally if the mail is accepted for at least one recipient. Otherwise it will raise an exception. That is, if this method does not raise an exception, then someone should get your mail. If this method does not raise an exception, it returns a dictionary, with one entry for each recipient that was refused. Each entry contains a tuple of the SMTP error code and the accompanying error message sent by the server.

M-Welsch commented 2 years ago

wrote test program

from base.common.mailer import Mailer
from os import urandom
from time import time

if __name__ == "__main__":
    bulkfile = "bulkfile.dings"
    bulkfile_size = 5e7
    with open(bulkfile, "wb") as fout:
        fout.write(urandom(int(bulkfile_size)))

    tick = time()
    Mailer().send_summary_bulk("bla")
    print(f"Mail without bulk took {time()-tick}s to complete")

    tick = time()
    Mailer().send_summary_bulk(bulkfile)
    print(f"Mail with {(bulkfile_size/1e6):.2f}MB bulk took {time()-tick}s to complete")

output

WARNING: Logger has been initialized with default values. Not for production.
27.09.2022 20:58:48 DEBUG: BaSe.base.common.config.bound: reloading config: base/config/notification.json
27.09.2022 20:58:57 INFO: BaSe.base.common.mailer: Email sent
Mail without bulk took 8.727355241775513s to complete
27.09.2022 20:58:57 DEBUG: BaSe.base.common.config.bound: reloading config: base/config/notification.json
27.09.2022 20:59:00 INFO: BaSe.base.common.mailer: Email sent
Mail with 50.00MB bulk took 3.1230289936065674s to complete

conclusion: eventhough the bulkfile is not really sent it shows that the completion of the mailer takes a significant amount of time. Therefore we close this issue with no need for any code change. @MaximilianStaab please notice.