|
1 | 1 | ---
|
2 |
| -title: 'Create a scheduled WebJob' |
| 2 | +title: 'Create a custom scheduled WebJob' |
3 | 3 | description: WebJobs on App Service enable you to automate repetitive tasks on your app. Learn how to create scheduled WebJobs in Azure App Service.
|
4 | 4 | ms.topic: tutorial
|
5 | 5 | ms.date: 5/1/2025
|
@@ -127,19 +127,19 @@ You can [download a pre-built sample project](https://github.com/Azure-Samples/A
|
127 | 127 |
|
128 | 128 | The Python script, `webjob.py`, outputs the current time to the console as shown below:
|
129 | 129 |
|
130 |
| - ```Python |
131 |
| - import datetime |
132 |
| - |
133 |
| - current_datetime = datetime.datetime.now() |
134 |
| - print(current_datetime) # Output: 2025-03-27 10:27:21.240752 |
135 |
| - ``` |
| 130 | +```Python |
| 131 | +import datetime |
| 132 | +
|
| 133 | +current_datetime = datetime.datetime.now() |
| 134 | +print(current_datetime) # Output: 2025-03-27 10:27:21.240752 |
| 135 | +``` |
136 | 136 |
|
137 | 137 | The file, `run.sh`, calls WebJob.py as shown below:
|
138 | 138 |
|
139 |
| - ```Bash |
140 |
| - #!/bin/bash |
141 |
| - /opt/python/3/bin/python3.13 webjob.py |
142 |
| - ``` |
| 139 | +```Bash |
| 140 | +#!/bin/bash |
| 141 | +/opt/python/3/bin/python3.13 webjob.py |
| 142 | +``` |
143 | 143 |
|
144 | 144 | ## Create a scheduled WebJob
|
145 | 145 |
|
@@ -185,24 +185,24 @@ You can [download a pre-built sample project](https://github.com/Azure-Samples/A
|
185 | 185 |
|
186 | 186 | The JavaScript, `webjob.js`, outputs the current time to the console as shown below:
|
187 | 187 |
|
188 |
| - ```JavaScript |
189 |
| - // Import the 'Date' object from JavaScript |
190 |
| - const currentTime = new Date(); |
191 |
| - |
192 |
| - // Format the time as a string |
193 |
| - const formattedTime = currentTime.toLocaleTimeString(); |
194 |
| - |
195 |
| - // Output the formatted time to the console |
196 |
| - console.log(`Current system time is: ${formattedTime}`); |
197 |
| - ``` |
| 188 | +```JavaScript |
| 189 | +// Import the 'Date' object from JavaScript |
| 190 | +const currentTime = new Date(); |
| 191 | +
|
| 192 | +// Format the time as a string |
| 193 | +const formattedTime = currentTime.toLocaleTimeString(); |
| 194 | +
|
| 195 | +// Output the formatted time to the console |
| 196 | +console.log(`Current system time is: ${formattedTime}`); |
| 197 | +``` |
198 | 198 |
|
199 | 199 | The file, `run.sh`, calls webjob.js as shown below:
|
200 | 200 |
|
201 |
| - ```Bash |
202 |
| - #!/bin/bash |
203 |
| - |
204 |
| - node webjob.js |
205 |
| - ``` |
| 201 | +```Bash |
| 202 | +#!/bin/bash |
| 203 | +
|
| 204 | +node webjob.js |
| 205 | +``` |
206 | 206 |
|
207 | 207 | ## Create a scheduled WebJob
|
208 | 208 |
|
@@ -251,42 +251,42 @@ WebJobs is a feature of Azure App Service that enables you to run a program
|
251 | 251 |
|
252 | 252 | The Java project located at `project/src/main/java/webjob/HelloWorld.java` outputs a message & the current time to the console.
|
253 | 253 |
|
254 |
| - ```Java |
255 |
| - import java.time.LocalDateTime; |
256 |
| - |
257 |
| - public class HelloWorld { |
258 |
| - |
259 |
| - public static void main(String[] args) { |
260 |
| - |
261 |
| - System.out.println("------------------------------------------------------------"); |
262 |
| - System.out.println("Hello World from WebJob: " + LocalDateTime.now()); |
263 |
| - System.out.println("------------------------------------------------------------"); |
264 |
| - } |
| 254 | +```Java |
| 255 | +import java.time.LocalDateTime; |
| 256 | +
|
| 257 | +public class HelloWorld { |
| 258 | +
|
| 259 | + public static void main(String[] args) { |
| 260 | +
|
| 261 | + System.out.println("------------------------------------------------------------"); |
| 262 | + System.out.println("Hello World from WebJob: " + LocalDateTime.now()); |
| 263 | + System.out.println("------------------------------------------------------------"); |
265 | 264 | }
|
266 |
| - ``` |
| 265 | +} |
| 266 | +``` |
267 | 267 |
|
268 | 268 | ### Build the Java WebJob
|
269 | 269 |
|
270 | 270 | 1. The `run.sh` script runs a jar with the name that set in the Maven configuration. This script will run when our WebJob is triggered.
|
271 | 271 |
|
272 |
| - ```bash |
273 |
| - java -jar webjob-artifact-1.0.0.jar |
274 |
| - ``` |
| 272 | +```bash |
| 273 | +java -jar webjob-artifact-1.0.0.jar |
| 274 | +``` |
275 | 275 |
|
276 | 276 | 1. Next, we compile the 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:
|
277 | 277 |
|
278 |
| - ```bash |
279 |
| - mvn install |
280 |
| - mvn package |
281 |
| - ``` |
| 278 | +```bash |
| 279 | +mvn install |
| 280 | +mvn package |
| 281 | +``` |
282 | 282 |
|
283 | 283 | The jar files will be located at `project/target/webjob-artifact-1.0.0.jar` after a successful build.
|
284 | 284 |
|
285 | 285 | 1. Move the jar file to the root of the git repo with `mv project/target/webjob-artifact-1.0.0.jar .` Next you package our application as a `.zip` file.
|
286 | 286 |
|
287 |
| - ```bash |
288 |
| - zip webjob.zip run.sh webjob-artifact-1.0.0.jar |
289 |
| - ``` |
| 287 | +```bash |
| 288 | +zip webjob.zip run.sh webjob-artifact-1.0.0.jar |
| 289 | +``` |
290 | 290 |
|
291 | 291 | ## Create a scheduled WebJob on Azure
|
292 | 292 |
|
@@ -333,23 +333,23 @@ You can [download a pre-built sample project](https://github.com/Azure-Samples/A
|
333 | 333 |
|
334 | 334 | The PHP script, `webjob.php`, outputs the current time to the console as shown below:
|
335 | 335 |
|
336 |
| - ```PHP |
337 |
| - <?php |
338 |
| - // Get the current time |
339 |
| - $current_time = date("Y-m-d H:i:s"); |
340 |
| - |
341 |
| - // Display the current time |
342 |
| - echo "The current time is: " . $current_time; |
343 |
| - ?> |
344 |
| - ``` |
| 336 | +```PHP |
| 337 | +<?php |
| 338 | +// Get the current time |
| 339 | +$current_time = date("Y-m-d H:i:s"); |
| 340 | +
|
| 341 | +// Display the current time |
| 342 | +echo "The current time is: " . $current_time; |
| 343 | +?> |
| 344 | +``` |
345 | 345 |
|
346 | 346 | The file, `run.sh`, calls webjob.php as shown below:
|
347 | 347 |
|
348 |
| - ```Bash |
349 |
| - #!/bin/bash |
350 |
| - |
351 |
| - php -f webjob.php |
352 |
| - ``` |
| 348 | +```Bash |
| 349 | +#!/bin/bash |
| 350 | +
|
| 351 | +php -f webjob.php |
| 352 | +``` |
353 | 353 |
|
354 | 354 | ## Create a scheduled WebJob
|
355 | 355 |
|
|
0 commit comments