Files
NScrapy/NScrapy.DownloaderShell/StatusUpdaterMiddleware.cs
Elendil 723a51ea62 Init ConfigManagement Component
Will use Zookeeper to manager the config for every node
Also changed some methed name in old design for the purpose of align naming practice
2018-06-27 01:31:28 +08:00

32 lines
1.1 KiB
C#

using NScrapy.Downloader;
using NScrapy.Infra;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace NScrapy.DownloaderShell
{
public class StatusUpdaterMiddleware: EmptyDownloaderMiddleware
{
private Process currentProcess = null;
const int megaBytes = 1024 * 1024;
public StatusUpdaterMiddleware()
{
currentProcess = Process.GetCurrentProcess();
}
public async override void PostDownload(IResponse response)
{
await RedisManager.Connection.GetDatabase().StringSetAsync(
$"NScrapy.DownloaderStatus.{Program.ID.ToString()}", string.Format("{{DownloaderCapbility:{0},RunningDownloaders:{1},RunningTime:{2},StartTime:{3},MemoryUsed:{4}MB, LastUpdate:{5}}}",
DownloaderContext.CurrentContext.DownloaderCapbility,
DownloaderContext.CurrentContext.RunningDownloader,
currentProcess.UserProcessorTime,
currentProcess.StartTime,
currentProcess.PrivateMemorySize64/megaBytes,
DateTime.Now));
}
}
}