Skip to content

Commit a722c4c

Browse files
authored
Add F# worker service template (#22042)
1 parent 6c7c3b8 commit a722c4c

24 files changed

+316
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Worker">
2+
3+
<PropertyGroup>
4+
<TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
5+
<UserSecretsId>dotnet-Company.Application1-53bc9b9d-9d6a-45d4-8429-2a2761773502</UserSecretsId>
6+
<NoDefaultLaunchSettingsFile Condition="'$(ExcludeLaunchSettings)' == 'True'">True</NoDefaultLaunchSettingsFile>
7+
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.Application1</RootNamespace>
8+
</PropertyGroup>
9+
10+
11+
<ItemGroup>
12+
<Compile Include="Worker.fs" />
13+
<Compile Include="Program.fs" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="${MicrosoftExtensionsHostingPackageVersion}" />
18+
</ItemGroup>
19+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Služba pracovního procesu",
5+
"description": "Šablona prázdného projektu pro vytvoření služby pracovního procesu"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Workerdienst",
5+
"description": "Eine leere Projektvorlage zum Erstellen eines Workerdiensts."
6+
}
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json.schemastore.org/dotnetcli.host",
3+
"symbolInfo": {
4+
"Framework": {
5+
"longName": "framework"
6+
},
7+
"skipRestore": {
8+
"longName": "no-restore",
9+
"shortName": ""
10+
},
11+
"ExcludeLaunchSettings": {
12+
"longName": "exclude-launch-settings",
13+
"shortName": ""
14+
}
15+
},
16+
"usageExamples": [
17+
""
18+
]
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Worker Service",
5+
"description": "An empty project template for creating a worker service."
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Servicio de trabajo",
5+
"description": "Una plantilla de proyecto vacío para crear un servicio de trabajo."
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Service Worker",
5+
"description": "Modèle de projet vide pour la création d'un service Worker."
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Servizio di ruolo di lavoro",
5+
"description": "Modello di progetto vuoto per la creazione di servizio del ruolo di lavoro."
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "ワーカー サービス",
5+
"description": "ワーカー サービスを作成するための空のプロジェクト テンプレート。"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "작업자 서비스",
5+
"description": "작업자 서비스를 만들기 위한 빈 프로젝트의 템플릿입니다."
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Usługa procesu roboczego",
5+
"description": "Szablon pustego projektu służący do tworzenia usługi procesu roboczego."
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Serviço de Trabalho",
5+
"description": "Um modelo de projeto vazio para criar um serviço de trabalho."
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Служба рабочих ролей",
5+
"description": "Шаблон пустого проекта для создания службы рабочих ролей."
6+
}
7+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "Microsoft",
4+
"classifications": [
5+
"Common",
6+
"Worker",
7+
"Web"
8+
],
9+
"name": "Worker Service",
10+
"generatorVersions": "[1.0.0.0-*)",
11+
"description": "An empty project template for creating a worker service.",
12+
"groupIdentity": "Microsoft.Worker.Empty",
13+
"precedence": "7000",
14+
"identity": "Microsoft.Worker.Empty.FSharp.5.0",
15+
"shortName": "worker",
16+
"tags": {
17+
"language": "F#",
18+
"type": "project"
19+
},
20+
"sourceName": "Company.Application1",
21+
"preferNameDirectory": true,
22+
"guids": [
23+
"53bc9b9d-9d6a-45d4-8429-2a2761773502"
24+
],
25+
"sources": [
26+
{
27+
"modifiers": [
28+
{
29+
"condition": "(ExcludeLaunchSettings)",
30+
"exclude": [
31+
"Properties/launchSettings.json"
32+
]
33+
}
34+
]
35+
}
36+
],
37+
"symbols": {
38+
"ExcludeLaunchSettings": {
39+
"type": "parameter",
40+
"datatype": "bool",
41+
"defaultValue": "false",
42+
"description": "Whether to exclude launchSettings.json from the generated template."
43+
},
44+
"Framework": {
45+
"type": "parameter",
46+
"description": "The target framework for the project.",
47+
"datatype": "choice",
48+
"choices": [
49+
{
50+
"choice": "net5.0",
51+
"description": "Target net5.0"
52+
}
53+
],
54+
"replaces": "net5.0",
55+
"defaultValue": "net5.0"
56+
},
57+
"copyrightYear": {
58+
"type": "generated",
59+
"generator": "now",
60+
"replaces": "copyrightYear",
61+
"parameters": {
62+
"format": "yyyy"
63+
}
64+
},
65+
"skipRestore": {
66+
"type": "parameter",
67+
"datatype": "bool",
68+
"description": "If specified, skips the automatic restore of the project on create.",
69+
"defaultValue": "false"
70+
}
71+
},
72+
"primaryOutputs": [
73+
{
74+
"path": "Company.Application1.fsproj"
75+
}
76+
],
77+
"defaultName": "WorkerService",
78+
"postActions": [
79+
{
80+
"condition": "(!skipRestore)",
81+
"description": "Restore NuGet packages required by this project.",
82+
"manualInstructions": [
83+
{
84+
"text": "Run 'dotnet restore'"
85+
}
86+
],
87+
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
88+
"continueOnError": true
89+
}
90+
]
91+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "Çalışan Hizmeti",
5+
"description": "Çalışan hizmeti oluşturmaya yönelik bir boş proje şablonu."
6+
}
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "http://json.schemastore.org/vs-2017.3.host",
3+
"name": {
4+
"text": "Worker Service",
5+
"package": "{0CD94836-1526-4E85-87D3-FB5274C5AFC9}",
6+
"id": "1025"
7+
},
8+
"description": {
9+
"text": "An empty project template for creating a worker service.",
10+
"package": "{0CD94836-1526-4E85-87D3-FB5274C5AFC9}",
11+
"id": "1026"
12+
},
13+
"order": 300,
14+
"icon": "vs-2017.3/Worker.png",
15+
"learnMoreLink": "https://go.microsoft.com/fwlink/?linkid=2072778",
16+
"uiFilters": [ "oneaspnet" ],
17+
"supportsDocker": true,
18+
"excludeLaunchSettings": false,
19+
"minFullFrameworkVersion": "4.6.1"
20+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "辅助角色服务",
5+
"description": "用于创建辅助角色服务的空项目模板。"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "1.0.0.0",
3+
"strings": {
4+
"name": "背景工作服務",
5+
"description": "用於建立背景工作服務的空白專案範本。"
6+
}
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Company.Application1
2+
3+
open System
4+
open System.Collections.Generic
5+
open System.Linq
6+
open System.Threading.Tasks
7+
open Microsoft.Extensions.DependencyInjection
8+
open Microsoft.Extensions.Hosting
9+
10+
module Program =
11+
let createHostBuilder args =
12+
Host.CreateDefaultBuilder(args)
13+
.ConfigureServices(fun hostContext services ->
14+
services.AddHostedService<Worker>() |> ignore)
15+
16+
[<EntryPoint>]
17+
let main args =
18+
createHostBuilder(args).Build().Run()
19+
20+
0 // exit code
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"profiles": {
3+
"Company.Application1": {
4+
"commandName": "Project",
5+
"environmentVariables": {
6+
"DOTNET_ENVIRONMENT": "Development"
7+
}
8+
}
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Company.Application1
2+
3+
open System
4+
open System.Collections.Generic
5+
open System.Linq
6+
open System.Threading
7+
open System.Threading.Tasks
8+
open Microsoft.Extensions.Hosting
9+
open Microsoft.Extensions.Logging
10+
11+
type Worker(logger: ILogger<Worker>) =
12+
inherit BackgroundService()
13+
14+
override _.ExecuteAsync(ct: CancellationToken) =
15+
async {
16+
while not ct.IsCancellationRequested do
17+
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now)
18+
do! Async.Sleep(1000)
19+
}
20+
|> Async.StartAsTask
21+
:> Task // need to convert into the parameter-less task
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)