Refactor: renamings, extract fn 'loop'

Renamings:
loop -> loop_step
delta -> next_mail_time (this variable names a point in time, not a duration)

Extracting the 'loop' fn is a preparation for later commits where a
second type of loop is added.
This commit is contained in:
Erik Arvstedt 2018-05-11 14:01:19 +02:00
parent e65e27d11f
commit bd75a65866

View File

@ -74,24 +74,27 @@ class Command(BaseCommand):
) )
if options["oneshot"]: if options["oneshot"]:
self.loop(mail_delta=mail_delta) self.loop_step(mail_delta)
else: else:
try: try:
while True: self.loop(loop_time, mail_delta)
self.loop(mail_delta=mail_delta)
time.sleep(loop_time)
if self.verbosity > 1:
print(".", int(time.time()))
except KeyboardInterrupt: except KeyboardInterrupt:
print("Exiting") print("Exiting")
def loop(self, mail_delta): def loop(self, loop_time, mail_delta):
while True:
self.loop_step(mail_delta)
time.sleep(loop_time)
if self.verbosity > 1:
print(".", int(time.time()))
def loop_step(self, mail_delta):
# Occasionally fetch mail and store it to be consumed on the next loop # Occasionally fetch mail and store it to be consumed on the next loop
# We fetch email when we first start up so that it is not necessary to # We fetch email when we first start up so that it is not necessary to
# wait for 10 minutes after making changes to the config file. # wait for 10 minutes after making changes to the config file.
delta = self.mail_fetcher.last_checked + mail_delta next_mail_time = self.mail_fetcher.last_checked + mail_delta
if self.first_iteration or delta < datetime.datetime.now(): if self.first_iteration or datetime.datetime.now() > next_mail_time:
self.first_iteration = False self.first_iteration = False
self.mail_fetcher.pull() self.mail_fetcher.pull()