You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/app-service/quickstart-webjobs.md
+56-43Lines changed: 56 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -238,67 +238,80 @@ WebJobs is a feature of Azure App Service that enables you to run a program
238
238
239
239
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
240
240
- An existing App Service [Java app](quickstart-java.md).
241
+
-[Maven Plugin for Azure App Service Web Apps](https://github.com/microsoft/azure-maven-plugins/blob/develop/azure-webapp-maven-plugin/README.md).
241
242
-**[Always on](configure-common.md?tabs=portal#configure-general-settings)** must be enabled on your app.
242
243
- Ensure the App setting `WEBSITE_SKIP_RUNNING_KUDUAGENT` is set to `false`.
243
244
244
245
## Create your sample WebJob
245
246
246
-
1.In this step, you create a basic .NET WebJob project and navigate to the project root.
247
+
[A sample Java WebJob](https://github.com/Azure-Samples/App-Service-Java-WebJobs-QuickStart) has been created for you. In this section, you review the sample and then build a `.JAR` file using Maven in the Cloud Shell.
247
248
248
-
```bash
249
-
dotnet new console -n webjob –framework net9.0
250
-
251
-
cd webjob
252
-
```
249
+
### Review the sample
253
250
254
-
1. Next, replace `Program.cs` to the following code that writes the current time to the console:
251
+
Digging into the code, our Java project located at `project/src/main/java/webjob/HelloWorld.java` is relatively simple. It just outputs a message & the current time to the console.
255
252
256
-
```dotnet
257
-
using System;
258
-
259
-
class Program
260
-
{
261
-
static void Main()
262
-
{
263
-
DateTimeOffset now = DateTimeOffset.Now;
264
-
Console.WriteLine("Current time with is: " + now.ToString("hh:mm:ss tt zzz"));
265
-
}
266
-
}
267
-
```
253
+
```Java
254
+
importjava.time.LocalDateTime;
268
255
269
-
1. From the *webjob* directory, run the webjob to confirm the current time is output to the console:
1. Once you've confirmed the app works, build it and navigate to the parent directory:
269
+
The run.sh script located at the root of our git repo, just runs a jar with the name that we’ve set in our maven configuration. This script will run when our WebJob is triggered, and it is the job of this script to kick off our Java executable (jar).
282
270
283
-
```bash
284
-
dotnet build --self-contained
285
-
286
-
cd ..
287
-
```
271
+
```bash
272
+
java -jar webjob-artifact-1.0.0.jar
273
+
```
288
274
289
-
1. Next we to create `run.sh` with the following code:
275
+
Now we need to compile our Java project to produce the executable jar. There are multiple ways to do this, but for this example, we’ll use Maven. Run the following commands from the `project/` directory:
290
276
291
-
```text
292
-
#!/bin/bash
293
-
294
-
dotnet webjob/bin/Debug/net9.0/webjob.dll
295
-
```
277
+
```bash
278
+
mvn install
279
+
mvn package
280
+
```
281
+
After successfully building our app with `mvn package`, our jar file will be located at `project/target/webjob-artifact-1.0.0.jar`.
296
282
297
-
1. Now package all the files into a .zip as shown below:
283
+
Now we have everything we need to assemble our zip file. Again, there are multiple ways to do this, but for this demo we’ll use the zip CLI utility to create our zip file called `webjob.zip`. First move your jar file to the root of the git repo with ` project/target/webjob-artifact-1.0.0.jar .` Then run the zip command to package our application as a zip file.
284
+
285
+
```bash
286
+
287
+
zip webjob.zip run.sh webjob-artifact-1.0.0.jar
288
+
289
+
```
290
+
## Create a scheduled WebJob on Azure
291
+
292
+
1. In the [Azure portal](https://portal.azure.com), go to the **App Service** page of your App Service app.
293
+
294
+
1. From the left pane, select **WebJobs**, then select **Add**.
298
295
299
-
```bash
300
-
zip webjob.zip run.sh webjob/bin/Debug/net9.0/*
301
-
```
296
+
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal (scheduled WebJob).":::
297
+
298
+
1. Fill in the **Add WebJob** settings as specified in the table, then select **Create Webjob**. For **File Upload**, be sure to select the .zip file you downloaded earlier in the [Download the sample WebJob](#download-the-sample-webjob) section.
299
+
300
+
:::image type="content" source="media/webjobs-create/configure-new-scheduled-webjob.png" alt-text="Screenshot that shows how to configure a scheduled WebJob in an App Service app.":::
|**Name**| webjob | The WebJob name. Must start with a letter or a number and must not contain special characters other than "-" and "_". |
305
+
|**File Upload**| App-Service-PHP-WebJobs-Quickstart-Main.zip | The *.zip* file that contains your executable or script file. The supported file types are listed in the [supported file types](webjobs-create.md?tabs=windowscode#acceptablefiles) section. |
306
+
|**Type**| Triggered | Specifies when the WebJob runs: Continuous or Triggered. |
307
+
|**Triggers**| Scheduled | Scheduled or Manual. Ensure [Always on](configure-common.md?tabs=portal#configure-general-settings) is enabled for the schedule to work reliably.|
308
+
|**CRON Expression**| 0 0/1 * * * * | For this quickstart, we use a schedule that runs every minute. See [CRON expressions](webjobs-create.md?tabs=windowscode#ncrontab-expressions) to learn more about the syntax. |
309
+
310
+
1. The new WebJob appears on the **WebJobs** page. If you see a message that says the WebJob was added, but you don't see it, select **Refresh**.
311
+
312
+
1. The scheduled WebJob is run at the schedule defined by the CRON expression.
313
+
314
+
:::image type="content" source="media/webjobs-create/scheduled-webjob-run.png" alt-text="Screenshot that shows how to run a manually scheduled WebJob in the Azure portal.":::
0 commit comments