mirror of
https://github.com/xboxeer/NScrapy.git
synced 2026-10-29 04:17:45 +08:00
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
32 lines
1.1 KiB
C#
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));
|
|
}
|
|
}
|
|
}
|