Debug logs in fetcher/sender, fixed error in HS

This commit is contained in:
2020-03-02 18:10:19 +04:00
parent a151c37f94
commit ef7d8a7d14
5 changed files with 12 additions and 3 deletions
+3 -1
View File
@@ -160,7 +160,9 @@ namespace Kruzya.TelegramBot.Core
private void HookAppDomain() private void HookAppDomain()
{ {
AppDomain.CurrentDomain.AssemblyResolve += delegate(object? sender, ResolveEventArgs args) var appDomain = AppDomain.CurrentDomain;
appDomain.AssemblyResolve += delegate(object? sender, ResolveEventArgs args)
{ {
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyPath = Path.Combine(basePath, new AssemblyName(args.Name).Name + ".dll"); string assemblyPath = Path.Combine(basePath, new AssemblyName(args.Name).Name + ".dll");
+2 -1
View File
@@ -3,13 +3,14 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BotFramework; using BotFramework;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Telegram.Bot.Exceptions; using Telegram.Bot.Exceptions;
using Telegram.Bot.Types; using Telegram.Bot.Types;
namespace Kruzya.TelegramBot.Core.Service namespace Kruzya.TelegramBot.Core.Service
{ {
public abstract class AbstractTimedHostedService public abstract class AbstractTimedHostedService : IHostedService, IDisposable
{ {
private Timer _timer; private Timer _timer;
+3 -1
View File
@@ -30,7 +30,9 @@ namespace Kruzya.TelegramBot.RichSiteSummary
services.AddQueue<UserMessage>() services.AddQueue<UserMessage>()
.AddQueue<UserUnsubscribe>(); .AddQueue<UserUnsubscribe>();
services.AddHostedService<RssFetch>(); services.AddHostedService<RssFetch>()
.AddHostedService<Unsubscriber>()
.AddHostedService<MessageSender>();
} }
} }
} }
@@ -36,6 +36,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
return; return;
} }
_logger.LogDebug($"Message for {message.ChatId.Identifier} dequeued.");
try try
{ {
await _bot.BotClient.SendTextMessageAsync(message.ChatId, message.Text, message.ParseMode, await _bot.BotClient.SendTextMessageAsync(message.ChatId, message.Text, message.ParseMode,
@@ -43,6 +44,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
} }
catch (ApiRequestException e) catch (ApiRequestException e)
{ {
_logger.LogDebug($"Message for {message.ChatId.Identifier} is failed: {e.Message}.");
if (!e.Message.Contains("bot was blocked by user")) if (!e.Message.Contains("bot was blocked by user"))
{ {
ReEnqueue(message, e, message.ChatId); // looks like a network issue ReEnqueue(message, e, message.ChatId); // looks like a network issue
@@ -58,6 +60,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
} }
catch (Exception e) catch (Exception e)
{ {
_logger.LogDebug($"Message for {message.ChatId.Identifier} is failed: {e.Message}.");
ReEnqueue(message, e); ReEnqueue(message, e);
} }
} }
@@ -156,6 +156,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
}; };
_queue.Enqueue(message); _queue.Enqueue(message);
_logger.LogDebug($"Enqueued message for {subscriber.SubscriberId}");
} }
} }
} }