Update sample web job template and dependencies (#251)
* Update SampleWebJob to use more recent template/dependencies. * Update SampleWebJob nuget references to avoid vulnerable libraries.
This commit is contained in:
Родитель
fdc5f40e46
Коммит
4e7dbeb552
|
@ -10,6 +10,8 @@ test/**/[Oo]bj/
|
|||
.binaries/
|
||||
msbuild.*
|
||||
/packages/
|
||||
samples/SampleWebApp/bin/
|
||||
samples/SampleWebApp/obj/
|
||||
samples/**/[Bb]in/
|
||||
samples/**/[Oo]bj/
|
||||
samples/**/[Pp]ublish[Pp]rofiles/
|
||||
samples/**/[Ss]ervice[Dd]ependencies/
|
||||
*.user
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using Microsoft.Azure.WebJobs;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SampleWebJob
|
||||
{
|
||||
|
@ -9,31 +10,35 @@ namespace SampleWebJob
|
|||
{
|
||||
// This function will get triggered/executed when a new message is written
|
||||
// on an Azure Queue called queue.
|
||||
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
|
||||
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, ILogger logger)
|
||||
{
|
||||
log.WriteLine("===================================================================");
|
||||
log.WriteLine("===================================================================");
|
||||
log.WriteLine(message);
|
||||
StringBuilder log = new StringBuilder();
|
||||
|
||||
log.WriteLine("---------- App Settings ----------");
|
||||
log.AppendLine("===================================================================");
|
||||
log.AppendLine("===================================================================");
|
||||
log.AppendLine(message);
|
||||
|
||||
log.AppendLine("---------- App Settings ----------");
|
||||
foreach (string appsetting in ConfigurationManager.AppSettings.Keys)
|
||||
{
|
||||
log.WriteLine($"{appsetting}\t{ConfigurationManager.AppSettings[appsetting]}");
|
||||
log.AppendLine($"{appsetting}\t{ConfigurationManager.AppSettings[appsetting]}");
|
||||
}
|
||||
|
||||
log.WriteLine("");
|
||||
log.WriteLine("---------- Connection Strings ----------");
|
||||
log.AppendLine("");
|
||||
log.AppendLine("---------- Connection Strings ----------");
|
||||
foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings)
|
||||
{
|
||||
log.WriteLine($"{cs.Name}\t{cs.ConnectionString}");
|
||||
log.AppendLine($"{cs.Name}\t{cs.ConnectionString}");
|
||||
}
|
||||
|
||||
log.WriteLine("");
|
||||
log.WriteLine("---------- Environment ----------");
|
||||
log.AppendLine("");
|
||||
log.AppendLine("---------- Environment ----------");
|
||||
foreach (DictionaryEntry ev in System.Environment.GetEnvironmentVariables())
|
||||
{
|
||||
log.WriteLine($"{ev.Key}\t{ev.Value}");
|
||||
log.AppendLine($"{ev.Key}\t{ev.Value}");
|
||||
}
|
||||
|
||||
logger.LogInformation(log.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,43 @@
|
|||
using System;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SampleWebJob
|
||||
{
|
||||
// To learn more about Microsoft Azure WebJobs SDK, please see https://go.microsoft.com/fwlink/?LinkID=320976
|
||||
// To learn more about Microsoft Azure WebJobs SDK, please see https://go.microsoft.com/fwlink/?linkid=2250384
|
||||
internal class Program
|
||||
{
|
||||
// Please set the following connection strings in app.config for this WebJob to run:
|
||||
// AzureWebJobsDashboard and AzureWebJobsStorage
|
||||
static void Main()
|
||||
// Please set AzureWebJobsStorage connection strings in appsettings.json for this WebJob to run.
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var config = new JobHostConfiguration();
|
||||
var builder = new HostBuilder()
|
||||
.UseEnvironment(EnvironmentName.Development)
|
||||
.ConfigureWebJobs(b =>
|
||||
{
|
||||
b.AddAzureStorageCoreServices()
|
||||
.AddAzureStorageQueues();
|
||||
})
|
||||
.ConfigureLogging((context, b) =>
|
||||
{
|
||||
b.SetMinimumLevel(LogLevel.Information);
|
||||
b.AddConsole();
|
||||
});
|
||||
|
||||
if (config.IsDevelopment)
|
||||
|
||||
var host = builder.Build();
|
||||
using (host)
|
||||
{
|
||||
config.UseDevelopmentSettings();
|
||||
}
|
||||
ILogger logger = host.Services.GetService(typeof(ILogger<Program>)) as ILogger<Program>;
|
||||
|
||||
// The following code ensures that the WebJob will be running continuously
|
||||
//var host = new JobHost(config);
|
||||
//host.RunAndBlock();
|
||||
Functions.ProcessQueueMessage("Manual trigger of ProcessMessageQ", Console.Out);
|
||||
await host.StartAsync();
|
||||
Functions.ProcessQueueMessage("Manual trigger of ProcessMessageQ", logger);
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net471</TargetFramework>
|
||||
|
@ -7,26 +6,26 @@
|
|||
<WebJobName>$(AssemblyName)</WebJobName>
|
||||
<WebJobType>Continuous</WebJobType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="System.Spatial" Version="5.8.4" />
|
||||
<PackageReference Include="Microsoft.Data.Edm" Version="5.8.4" />
|
||||
<PackageReference Include="Microsoft.Data.OData" Version="5.8.4" />
|
||||
<PackageReference Include="Microsoft.Data.Services.Client" Version="5.8.4" />
|
||||
<PackageReference Include="Microsoft.WindowsAzure.ConfigurationManager" Version="3.2.1" />
|
||||
<PackageReference Include="WindowsAzure.Storage" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="1.1.2" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs" Version="1.1.2" />
|
||||
<PackageReference Include="Microsoft.Azure.KeyVault.Core" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.41" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage.Queues" Version="5.3.3" />
|
||||
<PackageReference Include="Microsoft.Azure.WebJobs.Host.Storage" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
|
||||
<PackageReference Include="System.Text.Json" Version="6.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Base\Base.csproj" />
|
||||
<ProjectReference Include="..\..\src\Environment\Environment.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Configuration" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Settings.job">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
|
||||
// Examples:
|
||||
|
||||
// Runs every minute
|
||||
// "schedule": "0 * * * * *"
|
||||
|
||||
// Runs every 15 minutes
|
||||
// "schedule": "0 */15 * * * *"
|
||||
|
||||
// Runs every hour (i.e. whenever the count of minutes is 0)
|
||||
// "schedule": "0 0 * * * *"
|
||||
|
||||
// Runs every hour from 9 AM to 5 PM
|
||||
// "schedule": "0 0 9-17 * * *"
|
||||
|
||||
// Runs at 9:30 AM every day
|
||||
// "schedule": "0 30 9 * * *"
|
||||
|
||||
// Runs at 9:30 AM every week day
|
||||
// "schedule": "0 30 9 * * 1-5"
|
||||
}
|
|
@ -23,12 +23,7 @@
|
|||
add them back using the correct EnvironmentConfigBuilder, as demonstrated below. -->
|
||||
<appSettings configBuilders="AzureAppSettings" />
|
||||
|
||||
<connectionStrings configBuilders="AzureConnStr_Sql,AzureConnStr_MySql,AzureConnStr_SqlAzure,AzureConnStr_Postgres,AzureConnStr_Custom,Env32">
|
||||
<!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
|
||||
<!-- For local execution, the value can be set either in this config file or through environment variables -->
|
||||
<add name="AzureWebJobsDashboard" connectionString="" />
|
||||
<add name="AzureWebJobsStorage" connectionString="" />
|
||||
</connectionStrings>
|
||||
<connectionStrings configBuilders="AzureConnStr_Sql,AzureConnStr_MySql,AzureConnStr_SqlAzure,AzureConnStr_Postgres,AzureConnStr_Custom" />
|
||||
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
|
||||
}
|
Загрузка…
Ссылка в новой задаче