add jobserver

Former-commit-id: 58f8f8a2c3e502f44a44714821dca2f0cd4378da
TangShanKaiPing
wanggang 5 years ago
parent 9cccc7b374
commit 9e441fa71a

@ -20,3 +20,6 @@ dotnet_diagnostic.CA1031.severity = none
# CA1052: Static holder types should be Static or NotInheritable
dotnet_diagnostic.CA1052.severity = none
# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = none

@ -422,7 +422,7 @@ namespace Infrastructure.Web
public virtual void UseScheduler(IApplicationBuilder app)
{
app.UseHangfireDashboard();
app.UseHangfireDashboard(pathMatch: "/job");
app.UseHangfireServer();
}

@ -89,7 +89,7 @@ namespace IoTCenter.Services
var tigger = message.Data;
//if (tigger.Scene.NodeId == null)
{
Tiggers.TryRemove(message.Data.Id, out SceneTigger iotTigger);
Tiggers.TryRemove(message.Data.Id, out _);
Tiggers.TryAdd(tigger.Id, tigger);
}
}
@ -99,7 +99,7 @@ namespace IoTCenter.Services
var tigger = message.Data;
//if (tigger.Scene.NodeId == null)
{
Tiggers.TryRemove(message.Data.Id, out SceneTigger iotTigger);
Tiggers.TryRemove(message.Data.Id, out _);
Tiggers.TryAdd(tigger.Id, tigger);
}
}
@ -109,7 +109,7 @@ namespace IoTCenter.Services
var tigger = message.Data;
//if (tigger.Scene.NodeId == null)
{
Tiggers.TryRemove(tigger.Id, out SceneTigger iotTigger);
Tiggers.TryRemove(tigger.Id, out _);
}
}

@ -8,7 +8,6 @@ using System.Text;
namespace IoTNode
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1052:Static holder types should be Static or NotInheritable", Justification = "<挂起>")]
public class Program
{
public static void Main(string[] args)

@ -0,0 +1,18 @@
*.bak
*.suo
*.db
*.db-shm
*.db-wal
*.user
.vs
obj
Obj
bin
Bin
debug
Debug
release
Release
Logs
logs
node_modules

@ -0,0 +1,9 @@
using System;
namespace JobServer.Controllers
{
public class HomeController
{
public string Index() => DateTime.Now.ToString();
}
}

@ -0,0 +1,57 @@
using Hangfire;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Net.Http;
namespace JobServer.Controllers
{
public class RecurringJobController : Controller
{
private readonly IHttpClientFactory _httpClientFactory;
public RecurringJobController(IHttpClientFactory httpClientFactory)
{
this._httpClientFactory = httpClientFactory;
}
public string AddOrUpdate(string id, string url, string cron)
{
try
{
RecurringJob.AddOrUpdate<RecurringJobController>(id, o => o.Handle(id, url), cron);
return string.Empty;
}
catch (Exception ex)
{
return ex.ToString();
}
}
public string Remove(string id)
{
try
{
RecurringJob.RemoveIfExists(id);
return string.Empty;
}
catch (Exception ex)
{
return ex.ToString();
}
}
private void Handle(string id, string url)
{
var wc = this._httpClientFactory.CreateClient();
try
{
using var content = new StringContent(id);
wc.PostAsync(url, content);
}
catch (HttpRequestException ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<Version>1.0.0-beta.410</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.10" />
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.2" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
</ItemGroup>
</Project>

@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace JobServer.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
{
public string RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}

@ -0,0 +1,10 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace JobServer.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
}
}

@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace JobServer.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;
public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
}
}

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - JobServer</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">JobServer</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2020 - JobServer - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Scripts", required: false)
</body>
</html>

@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

@ -0,0 +1,3 @@
@using JobServer
@namespace JobServer.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}

@ -0,0 +1,36 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using System.IO;
using System.Text;
namespace JobServer
{
public class Program
{
public static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true)
.Build();
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.ConfigureLogging((c, o) =>
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(config)
.WriteTo.Console()
.WriteTo.File("logs/log.txt", rollOnFileSizeLimit: true, fileSizeLimitBytes: 100 * 1024 * 1024, rollingInterval: RollingInterval.Infinite)
.CreateLogger();
o.AddSerilog();
})
.UseStartup<Startup>()
.Build()
.Run();
}
}
}

@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8013",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"JobServer": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:8013",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,86 @@
using Hangfire;
using Hangfire.MySql;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Transactions;
namespace JobServer
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
private readonly string _origins = "AllowAllHeaders";
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options => options.AddPolicy(_origins,
builder =>
{
builder.SetIsOriginAllowed(o => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
})
);
services.AddHttpClient();
services.AddControllersWithViews();
var connectionString = Configuration.GetConnectionString("HangfireConnection");
services.AddHangfire(configuration => configuration.UseStorage(new MySqlStorage(connectionString, new MySqlStorageOptions
{
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
QueuePollInterval = TimeSpan.FromSeconds(15),
JobExpirationCheckInterval = TimeSpan.FromHours(1),
CountersAggregateInterval = TimeSpan.FromMinutes(5),
PrepareSchemaIfNecessary = true,
DashboardJobListLimit = 50000,
TransactionTimeout = TimeSpan.FromMinutes(1),
TablesPrefix = "Hangfire"
})));
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
string basePath = this.Configuration.GetValue<String>("BasePath", "");
app.UsePathBase(basePath);
app.UseHangfireDashboard(pathMatch: "/job");
app.UseHangfireServer();
app.UseCors(_origins);
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

@ -0,0 +1,13 @@
{
"server.urls": "http://*:8013",
"BasePath": "/JobServer",
"ConnectionStrings": {
"HangfireConnection": "Server=127.0.0.1;Port=3306;Database=jobserver;Uid=root;Pwd=root;Allow User Variables=True;"
},
"Logging": {
"LogLevel": {
"Default": "Warning",
"Hangfire": "Information"
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

@ -39,6 +39,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UI", "UI", "{11BCB5F9-0020-
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebSPA", "WebSPA\WebSPA.csproj", "{6F839910-580D-4CD1-A0C0-6FAF542B4480}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JobServer", "JobServer\JobServer.csproj", "{6E2766D8-9ECF-469E-8662-A20F673E52CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -145,6 +147,18 @@ Global
{6F839910-580D-4CD1-A0C0-6FAF542B4480}.Release|iPhone.Build.0 = Release|Any CPU
{6F839910-580D-4CD1-A0C0-6FAF542B4480}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{6F839910-580D-4CD1-A0C0-6FAF542B4480}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Debug|iPhone.Build.0 = Debug|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Release|Any CPU.Build.0 = Release|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Release|iPhone.ActiveCfg = Release|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Release|iPhone.Build.0 = Release|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{6E2766D8-9ECF-469E-8662-A20F673E52CC}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -158,9 +172,10 @@ Global
{BE6DEBC5-004F-4811-8BDC-67C74D9E8C2F} = {AE34E06D-C5C7-44BC-B168-85808318516C}
{C66B39B3-D863-4651-99CD-74104CA65C47} = {11BCB5F9-0020-463A-92FB-BC25E2A0BF75}
{6F839910-580D-4CD1-A0C0-6FAF542B4480} = {11BCB5F9-0020-463A-92FB-BC25E2A0BF75}
{6E2766D8-9ECF-469E-8662-A20F673E52CC} = {E1681DC3-9AC2-4FF6-B3DE-37EF826E6F8A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B7095FB-5E70-4EF8-805A-CB4A91AE4B0A}
BuildVersion_StartDate = 2000/1/1
SolutionGuid = {0B7095FB-5E70-4EF8-805A-CB4A91AE4B0A}
EndGlobalSection
EndGlobal

@ -8,6 +8,7 @@ echo d|xcopy "./src" "./dist/" /s /e /y /f
dotnet publish ../projects/WebMvc/WebMvc.csproj -c Release -r linux-x64 -o ../publish/dist/linux-x64/publish/apps/WebMVC
dotnet publish ../projects/WebSPA/WebSPA.csproj -c Release -r linux-x64 -o ../publish/dist/linux-x64/publish/apps/WebSPA
dotnet publish ../projects/UserCenter/UserCenter.csproj -c Release -r linux-x64 -o ../publish/dist/linux-x64/publish/apps/UserCenter
dotnet publish ../projects/JobServer/JobServer.csproj -c Release -r linux-x64 -o ../publish/dist/linux-x64/publish/apps/JobServer
dotnet publish ../projects/IoTCenter/IoTCenter.csproj -c Release -r linux-x64 -o ../publish/dist/linux-x64/publish/apps/IoTCenter
dotnet publish ../projects/IoTNode/IoTNode.csproj -c Release -r linux-arm64 -o ../publish/dist/linux-arm64/publish/apps/IoTNode

@ -0,0 +1,8 @@
[program:jobserver]
command=/root/publish/apps/JobServer/JobServer
directory=/root/publish/apps/JobServer/
autostart=true
autorestart=true
user=root
stdout_logfile=/root/publish/logs/iotcenter.log
stderr_logfile=/root/publish/logs/jobserver.err
Loading…
Cancel
Save