From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,NO_DNS_FOR_FROM, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from [192.168.1.2] (unknown [101.128.126.135]) by gnuweeb.org (Postfix) with ESMTPSA id 5C23A7E4BC; Wed, 4 Jan 2023 06:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1672813883; bh=4QLUboCsIMOFTQCrefJvHcuMf7tjtXSwSxJ1fafertg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=cPnPUcRhdU1Cbt0F8NizqfUxD8Trz/XTzfpk0jtVg0qOqKvB+BiXr7GYZ+y2P/hyN W4tRrmMS1ZaFJmIwxvRqan+Bz6AoJnv9HFbiohasr4H/Tw8xky+efwFgg7Fu4YrcxJ yqboxWMgtU7xx2Dbajj6iSP2Z0awFvkQGC1q4yGrenGwzVf7dnsgEZaoVZwBu2RDdM qz8tSxF+/8U/OHYD//WwuBoQyFQRLV/NxYe+ulVNceST/h37deMcDsM3tF/lxt5zZZ qKos3636G4Ecx5mCKxf1+v1Ip+sidYNsL11suVdencR0OEVlg8OkKd29KeG8LSmNTs cVGSywINSnu7A== Message-ID: Date: Wed, 4 Jan 2023 13:31:17 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v1 03/13] refactor(telegram)!: Ensure the Telegram bot has been started To: Alviro Iskandar Setiawan , Ammar Faizi Cc: GNU/Weeb Mailing List References: <20230103063641.1680-1-kiizuha@gnuweeb.org> <20230103063641.1680-4-kiizuha@gnuweeb.org> <5fa120d7-32ab-b560-0c8f-0da64546cf0b@gnuweeb.org> Content-Language: en-US From: Muhammad Rizki In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: On 04/01/2023 05.27, Alviro Iskandar Setiawan wrote: > On Wed, Jan 4, 2023 at 5:11 AM Ammar Faizi wrote: >> On 1/3/23 7:17 PM, Muhammad Rizki wrote: >>> No, we should use this method rather than `client.run()`. Why? because >>> at the previous commit, we use `client.run()` after the `bot.run()` >>> which is the `bot` here is running first before the Telegram bot is >>> started/connect to the Telegram MTProto API, previous commit: >>> >>> sched.start() >>> >>> bot.run() <- we listen for new emails, if error may >>> happen, the listener will send the log file >>> which is require to interact with the Telegram >>> API. >>> >>> client.run() <- The client is late to start/connect to the >>> Telegram API. >> >> What does this call ordering have to do with 'idle()'? > > because the subsequent code calls client.stop(), what if you don't > call client.stop()? but > > bot.run() # internally calls sched.start() How about I do the refactoring again like this? async def run(self): # this is Bot() class client.start() self.runner = self.sched.add_job( func=self.__run, misfire_grace_time=None, max_instances=1 ) self.sched.start() idle() client.stop() So, in the main file just call it `bot.run()`. What do you think?