@@ -76,35 +76,32 @@ def _run(self): # type: ignore[no-untyped-def]
7676 raise
7777
7878 def _run_impl (self ): # type: ignore[no-untyped-def]
79- self .sync_thread = InterruptibleThread (
80- retry_with_logging ,
81- self .sync ,
82- account_id = self .account_id ,
83- provider = self .provider_name ,
84- logger = self .log ,
85- )
86- self .sync_thread .start ()
87- self .sync_thread .join ()
88-
89- if self .sync_thread .successful ():
90- self ._cleanup ()
79+ try :
80+ retry_with_logging (
81+ self .sync ,
82+ account_id = self .account_id ,
83+ provider = self .provider_name ,
84+ logger = self .log ,
85+ )
86+ except Exception :
87+ self .log .exception (
88+ "mail sync raised an exception" , provider = self .provider_name
89+ )
90+ raise
91+ else :
9192 self .log .info (
9293 "mail sync finished successfully" , provider = self .provider_name
9394 )
94- return
95-
96- self .log .error (
97- "mail sync raised an exception" ,
98- provider = self .provider_name ,
99- exc = self .sync_thread .exception ,
100- )
101- raise self .sync_thread .exception # type: ignore[misc]
95+ finally :
96+ self ._cleanup ()
10297
10398 def sync (self ) -> Never :
10499 raise NotImplementedError
105100
101+ def stop (self ) -> None :
102+ raise NotImplementedError
103+
106104 def _cleanup (self ) -> None :
107- self .sync_thread .kill ()
108105 with session_scope (self .namespace_id ) as mailsync_db_session :
109106 for x in self .folder_monitors : # type: ignore[attr-defined]
110107 x .set_stopped (mailsync_db_session )
0 commit comments