Commit d75c0559 by guanzhenshan

增加docker支持

parent 3ef2d18a
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
......
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.DailySemiPurchaseSellStock/Bailun.DC.DailySemiPurchaseSellStock.csproj Bailun.DC.DailySemiPurchaseSellStock/
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.DailySemiPurchaseSellStock/Bailun.DC.DailySemiPurchaseSellStock.csproj
COPY . .
WORKDIR /src/Bailun.DC.DailySemiPurchaseSellStock
RUN dotnet build Bailun.DC.DailySemiPurchaseSellStock.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Bailun.DC.DailySemiPurchaseSellStock.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Bailun.DC.DailySemiPurchaseSellStock.dll"]
......@@ -7,28 +7,28 @@ namespace Bailun.DC.DailySemiPurchaseSellStock
{
class Program
{
//static async Task Main(string[] args)
//{
// Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
// {
// services.AddHostedService<Services>();
// });
// await builder.RunConsoleAsync();
//}
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) =>
{
Console.WriteLine(start);
_services.Init(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-09-01");
// while (start.AddDays(1) < DateTime.Now)
// {
// Console.WriteLine(start);
// _services.Init(start);
// start = start.AddDays(1);
// }
//}
}
}
using Bailun.DC.Models;
using Dapper;
using Microsoft.Extensions.Hosting;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Bailun.DC.DailySemiPurchaseSellStock
{
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) //每天 5:01分启动
{
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, int count = 0)
{
try
......
......@@ -76,3 +76,10 @@ services:
context: .
dockerfile: Bailun.DC.MonthSaleProfit/Dockerfile
bailun.dc.dailysemipurchasesellstock:
image: ${DOCKER_REGISTRY}bailundcdailysemipurchasesellstock
build:
context: .
dockerfile: Bailun.DC.DailySemiPurchaseSellStock/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