Skip to content

Commit a3afaa8

Browse files
authored
Merge pull request #98802 from ggailey777/webjobs
WebJobs freshness updates
2 parents 7ff22e7 + dc4c9c5 commit a3afaa8

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

articles/app-service/webjobs-sdk-get-started.md

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,31 @@ This article shows you how to deploy WebJobs as a .NET Core console app. To depl
3434

3535
## WebJobs NuGet packages
3636

37-
1. Install the latest stable 3.x version of the `Microsoft.Azure.WebJobs.Extensions` NuGet package, which includes `Microsoft.Azure.WebJobs`.
37+
1. Install the latest stable 3.x version of the [`Microsoft.Azure.WebJobs.Extensions` NuGet package](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions/), which includes `Microsoft.Azure.WebJobs`.
3838

39-
Here's the **Package Manager Console** command for version 3.0.2:
39+
Here's the **Package Manager Console** command:
4040

4141
```powershell
42-
Install-Package Microsoft.Azure.WebJobs.Extensions -version 3.0.2
42+
Install-Package Microsoft.Azure.WebJobs.Extensions -version <3_X_VERSION>
4343
```
4444
45+
In this command, replace `<3_X_VERSION>` with a supported version of the package.
46+
4547
## Create the Host
4648
4749
The host is the runtime container for functions that listens for triggers and calls functions. The following steps create a host that implements [`IHost`](/dotnet/api/microsoft.extensions.hosting.ihost), which is the Generic Host in ASP.NET Core.
4850
49-
1. In *Program.cs*, add a `using` statement:
51+
1. In *Program.cs*, add these `using` statements:
5052
5153
```cs
54+
using System.Threading.Tasks;
5255
using Microsoft.Extensions.Hosting;
5356
```
5457
5558
1. Replace the `Main` method with the following code:
5659
5760
```cs
58-
static void Main(string[] args)
61+
static async Task Main()
5962
{
6063
var builder = new HostBuilder();
6164
builder.ConfigureWebJobs(b =>
@@ -65,7 +68,7 @@ The host is the runtime container for functions that listens for triggers and ca
6568
var host = builder.Build();
6669
using (host)
6770
{
68-
host.Run();
71+
await host.RunAsync();
6972
}
7073
}
7174
```
@@ -76,12 +79,12 @@ In ASP.NET Core, host configurations are set by calling methods on the [`HostBui
7679
7780
In this section, you set up console logging that uses the [ASP.NET Core logging framework](/aspnet/core/fundamentals/logging).
7881
79-
1. Install the latest stable version of the `Microsoft.Extensions.Logging.Console` NuGet package, which includes `Microsoft.Extensions.Logging`.
82+
1. Install the latest stable version of the [`Microsoft.Extensions.Logging.Console` NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console/), which includes `Microsoft.Extensions.Logging`.
8083
81-
Here's the **Package Manager Console** command for version 2.2.0:
84+
Here's the **Package Manager Console** command:
8285
8386
```powershell
84-
Install-Package Microsoft.Extensions.Logging.Console -version 2.2.0
87+
Install-Package Microsoft.Extensions.Logging.Console -version <3_X_VERSION>
8588
```
8689

8790
1. In *Program.cs*, add a `using` statement:
@@ -90,6 +93,8 @@ In this section, you set up console logging that uses the [ASP.NET Core logging
9093
using Microsoft.Extensions.Logging;
9194
```
9295

96+
In this command, replace `<3_X_VERSION>` with a supported 3.x version of the package.
97+
9398
1. Call the [`ConfigureLogging`](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderextensions.configurelogging) method on [`HostBuilder`](/dotnet/api/microsoft.extensions.hosting.hostbuilder). The [`AddConsole`](/dotnet/api/microsoft.extensions.logging.consoleloggerextensions.addconsole) method adds console logging to the configuration.
9499

95100
```cs
@@ -102,7 +107,7 @@ In this section, you set up console logging that uses the [ASP.NET Core logging
102107
The `Main` method now looks like this:
103108

104109
```cs
105-
static void Main(string[] args)
110+
static async Task Main()
106111
{
107112
var builder = new HostBuilder();
108113
builder.ConfigureWebJobs(b =>
@@ -116,7 +121,7 @@ In this section, you set up console logging that uses the [ASP.NET Core logging
116121
var host = builder.Build();
117122
using (host)
118123
{
119-
host.Run();
124+
await host.RunAsync();
120125
}
121126
}
122127
```
@@ -134,11 +139,13 @@ Starting with version 3.x, you must explicitly install the Storage binding exten
134139

135140
1. Install the latest stable version of the [Microsoft.Azure.WebJobs.Extensions.Storage](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Storage) NuGet package, version 3.x.
136141
137-
Here's the **Package Manager Console** command for version 3.0.4:
142+
Here's the **Package Manager Console** command:
138143

139144
```powershell
140-
Install-Package Microsoft.Azure.WebJobs.Extensions.Storage -Version 3.0.4
145+
Install-Package Microsoft.Azure.WebJobs.Extensions.Storage -Version <3_X_VERSION>
141146
```
147+
148+
In this command, replace `<3_X_VERSION>` with a supported version of the package.
142149

143150
2. In the `ConfigureWebJobs` extension method, call the `AddAzureStorage` method on the [`HostBuilder`](/dotnet/api/microsoft.extensions.hosting.hostbuilder) instance to initialize the Storage extension. At this point, the `ConfigureWebJobs` method looks like the following example:
144151

@@ -155,22 +162,22 @@ Starting with version 3.x, you must explicitly install the Storage binding exten
155162
1. Right-click the project, select **Add** > **New Item...**, choose **Class**, name the new C# class file *Functions.cs*, and select **Add**.
156163

157164
1. In Functions.cs, replace the generated template with the following code:
158-
159-
```cs
160-
using Microsoft.Azure.WebJobs;
161-
using Microsoft.Extensions.Logging;
162-
163-
namespace WebJobsSDKSample
164-
{
165-
public class Functions
166-
{
167-
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, ILogger logger)
168-
{
169-
logger.LogInformation(message);
170-
}
171-
}
172-
}
173-
```
165+
166+
```cs
167+
using Microsoft.Azure.WebJobs;
168+
using Microsoft.Extensions.Logging;
169+
170+
namespace WebJobsSDKSample
171+
{
172+
public class Functions
173+
{
174+
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, ILogger logger)
175+
{
176+
logger.LogInformation(message);
177+
}
178+
}
179+
}
180+
```
174181

175182
The `QueueTrigger` attribute tells the runtime to call this function when a new message is written on an Azure Storage queue called `queue`. The contents of the queue message are provided to the method code in the `message` parameter. The body of the method is where you process the trigger data. In this example, the code just logs the message.
176183

@@ -348,21 +355,22 @@ In this section, you do the following tasks to set up Application Insights loggi
348355

349356
To take advantage of [Application Insights](../azure-monitor/app/app-insights-overview.md) logging, update your logging code to do the following:
350357

351-
* Add an Application Insights logging provider with default [filtering](webjobs-sdk-how-to.md#log-filtering); all Information and higher-level logs goes to both the console and Application Insights when you're running locally.
358+
* Add an Application Insights logging provider with default [filtering](webjobs-sdk-how-to.md#log-filtering). When running locally, all Information and higher-level logs are written to both the console and Application Insights.
352359
* Put the [LoggerFactory](./webjobs-sdk-how-to.md#logging-and-monitoring) object in a `using` block to ensure that log output is flushed when the host exits.
353360

354-
1. Install the latest stable 3.x version of the NuGet package for the Application Insights logging provider: `Microsoft.Azure.WebJobs.Logging.ApplicationInsights`.
361+
1. Install the latest stable 3.x version of the [`Microsoft.Azure.WebJobs.Logging.ApplicationInsights` NuGet package](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/).
355362
356-
Here's the **Package Manager Console** command for version 3.0.2:
363+
Here's the **Package Manager Console** command:
357364

358365
```powershell
359-
Install-Package Microsoft.Azure.WebJobs.Logging.ApplicationInsights -Version 3.0.2
366+
Install-Package Microsoft.Azure.WebJobs.Logging.ApplicationInsights -Version <3_X_VERSION>
360367
```
368+
In this command, replace `<3_X_VERSION>` with a supported version of the package.
361369

362370
1. Open *Program.cs* and replace the code in the `Main` method with the following code:
363371

364372
```cs
365-
static void Main(string[] args)
373+
static async Task Main()
366374
{
367375
var builder = new HostBuilder();
368376
builder.UseEnvironment(EnvironmentName.Development);
@@ -385,7 +393,7 @@ To take advantage of [Application Insights](../azure-monitor/app/app-insights-ov
385393
var host = builder.Build();
386394
using (host)
387395
{
388-
host.Run();
396+
await host.RunAsync();
389397
}
390398
}
391399
```

articles/app-service/webjobs-sdk-how-to.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ Automatic triggers call a function in response to an event. Consider this exampl
152152
```cs
153153
public static void Run(
154154
[QueueTrigger("myqueue-items")] string myQueueItem,
155-
[Blob("samples-workitems/{myQueueItem}", FileAccess.Read)] Stream myBlob,
155+
[Blob("samples-workitems/{queueTrigger}", FileAccess.Read)] Stream myBlob,
156156
ILogger log)
157157
{
158158
log.LogInformation($"BlobInput processed blob\n Name:{myQueueItem} \n Size: {myBlob.Length} bytes");
159159
}
160160
```
161161

162-
The `QueueTrigger` attribute tells the runtime to call the function whenever a queue message appears in the `myqueue-items` queue. The `Blob` attribute tells the runtime to use the queue message to read a blob in the *sample-workitems* container. The content of the queue message, passed in to the function in the `myQueueItem` parameter, is the name of the blob.
162+
The `QueueTrigger` attribute tells the runtime to call the function whenever a queue message appears in the `myqueue-items` queue. The `Blob` attribute tells the runtime to use the queue message to read a blob in the *sample-workitems* container. The name of the blob item in the `samples-workitems` container is obtained directly from the queue trigger as a binding expression (`{queueTrigger}`).
163163

164164
[!INCLUDE [webjobs-always-on-note](../../includes/webjobs-always-on-note.md)]
165165

0 commit comments

Comments
 (0)