Update .NET Core image and log every message

This commit is contained in:
2019-07-30 13:48:12 -04:00
parent 51954f38b2
commit 02a30346c2
2 changed files with 7 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-preview6-buster-slim-arm32v7 AS base FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-preview7-buster-slim-arm32v7 AS base
WORKDIR /app WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100-preview6-buster AS build FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100-preview7-buster AS build
WORKDIR /src WORKDIR /src
COPY ["./SerialReader.csproj", "./"] COPY ["./SerialReader.csproj", "./"]
RUN dotnet restore -r linux-arm "SerialReader.csproj" RUN dotnet restore -r linux-arm "SerialReader.csproj"

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration; using ChrisKaczor.HomeMonitor.Weather.Models;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json; using Newtonsoft.Json;
using RabbitMQ.Client; using RabbitMQ.Client;
using System; using System;
@@ -6,20 +7,16 @@ using System.IO.Ports;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using ChrisKaczor.HomeMonitor.Weather.Models;
namespace ChrisKaczor.HomeMonitor.Weather.SerialReader namespace ChrisKaczor.HomeMonitor.Weather.SerialReader
{ {
internal static class Program internal static class Program
{ {
private static IConfiguration _configuration; private static IConfiguration _configuration;
private static bool _boardStarting;
private static readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource(); private static readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
private static DateTime _lastLogTime = DateTime.MinValue;
private static long _messageCount;
private static bool _boardStarting;
private static void Main() private static void Main()
{ {
WriteLog("Starting"); WriteLog("Starting");
@@ -105,6 +102,8 @@ namespace ChrisKaczor.HomeMonitor.Weather.SerialReader
continue; continue;
} }
WriteLog($"Message received: {message}");
var weatherMessage = WeatherMessage.Parse(message); var weatherMessage = WeatherMessage.Parse(message);
var messageString = JsonConvert.SerializeObject(weatherMessage); var messageString = JsonConvert.SerializeObject(weatherMessage);
@@ -116,16 +115,6 @@ namespace ChrisKaczor.HomeMonitor.Weather.SerialReader
properties.Persistent = true; properties.Persistent = true;
model.BasicPublish(string.Empty, _configuration["Weather:Queue:Name"], properties, body); model.BasicPublish(string.Empty, _configuration["Weather:Queue:Name"], properties, body);
_messageCount++;
if ((DateTime.Now - _lastLogTime).TotalMinutes < 1)
continue;
WriteLog($"Number of messages received since {_lastLogTime} = {_messageCount}");
_lastLogTime = DateTime.Now;
_messageCount = 0;
} }
catch (TimeoutException) catch (TimeoutException)
{ {