Commit 84dadba4 by guanzhenshan

增加docker支持

parent 70c9abf0
FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY Bailun.DC.DailyPurchaseSellStock/Bailun.DC.DailyPurchaseSellStock.csproj Bailun.DC.DailyPurchaseSellStock/
COPY Bailun.DC.Common/Bailun.DC.Common.csproj Bailun.DC.Common/
COPY Bailun.DC.Models/Bailun.DC.Models.csproj Bailun.DC.Models/
RUN dotnet restore Bailun.DC.DailyPurchaseSellStock/Bailun.DC.DailyPurchaseSellStock.csproj
COPY . .
WORKDIR /src/Bailun.DC.DailyPurchaseSellStock
RUN dotnet build Bailun.DC.DailyPurchaseSellStock.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Bailun.DC.DailyPurchaseSellStock.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Bailun.DC.DailyPurchaseSellStock.dll"]
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
namespace Bailun.DC.DailyPurchaseSellStock
{
class Program
{
static void Main(string[] args)
static async Task Main(string[] args)
{
var _services = new Services();
var start = DateTime.Parse("2019-09-01");
while (start.AddDays(1) < DateTime.Now)
Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
_services.Init(start);
Console.WriteLine(start);
start = start.AddDays(1);
}
services.AddHostedService<Services>();
});
await builder.RunConsoleAsync();
}
//static void Main(string[] args)
//{
// var _services = new Services();
// var start = DateTime.Parse("2019-10-24");
// while (start.AddDays(1) < DateTime.Now)
// {
// _services.Init(start);
// Console.WriteLine(start);
// start = start.AddDays(1);
// }
//}
}
}
......@@ -5,12 +5,46 @@ using MySql.Data.MySqlClient;
using Dapper;
using System.Linq;
using Bailun.DC.Models;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Extensions.Hosting;
namespace Bailun.DC.DailyPurchaseSellStock
{
public class Services
public class Services : BackgroundService
{
private Timer _timer;
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
return Task.CompletedTask;
}
private void DoWork(object state)
{
try
{
var now = DateTime.Now;
if (now.Hour == 5 && now.Minute == 01) //每天 23:59分启动
{
Console.WriteLine("开始启动 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var start = DateTime.Parse(now.AddDays(-1).ToShortDateString());
Init(start);
Console.WriteLine("任务运行完成 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void Init(DateTime day)
{
var sql = $@"select t1.bailun_sku,t1.warehouse_code,t2.warehouse_name,sum(t1.usable_stock+t1.occupy_stock) count,sum((t1.usable_stock+t1.occupy_stock)*t1.unit_price) as amount from dc_daily_stock t1
......
......@@ -62,3 +62,10 @@ services:
context: .
dockerfile: ../Bailun.DC.DailyPayAndIncoming/Dockerfile
bailun.dc.dailypurchasesellstock:
image: ${DOCKER_REGISTRY}bailundcdailypurchasesellstock
build:
context: .
dockerfile: Bailun.DC.DailyPurchaseSellStock/Dockerfile
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment