Skip to content

Commit 35fb95d

Browse files
committed
Work on timer trigger.
1 parent 4fc74f2 commit 35fb95d

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

articles/azure-functions/functions-bindings-service-bus-output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Push-OutputBinding -Name outputSbMsg -Value @{
233233
::: zone-end
234234
::: zone pivot="programming-language-python"
235235

236-
The following example demonstrates how to write out to a Service Bus queue in Python.
236+
The following example demonstrates how to write out to a Service Bus queue in Python. The example depends on whether you use the [v1 or v2 Python programming model](functions-reference-python.md).
237237

238238
# [v2](#tab/python-v2)
239239

articles/azure-functions/functions-bindings-service-bus-trigger.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Write-Host "PowerShell ServiceBus queue trigger function processed message: $myS
206206
::: zone-end
207207
::: zone pivot="programming-language-python"
208208

209-
The following example demonstrates how to read a Service Bus queue message via a trigger.
209+
The following example demonstrates how to read a Service Bus queue message via a trigger. The example depends on whether you use the [v1 or v2 Python programming model](functions-reference-python.md).
210210

211211
# [v2](#tab/python-v2)
212212

articles/azure-functions/functions-bindings-timer.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Timer trigger for Azure Functions
33
description: Understand how to use timer triggers in Azure Functions.
44
ms.assetid: d2f013d1-f458-42ae-baf8-1810138118ac
55
ms.topic: reference
6-
ms.date: 03/04/2022
6+
ms.date: 03/06/2023
77
ms.devlang: csharp, java, javascript, powershell, python
88
ms.custom: "devx-track-csharp, devx-track-python"
99
zone_pivot_groups: programming-languages-set-functions-lang-workers
@@ -21,6 +21,23 @@ For information on how to manually run a timer-triggered function, see [Manually
2121

2222
Source code for the timer extension package is in the [azure-webjobs-sdk-extensions](https://github.com/Azure/azure-webjobs-sdk-extensions/blob/master/src/WebJobs.Extensions/Extensions/Timers/) GitHub repository.
2323

24+
::: zone pivot="programming-language-python"
25+
Azure Functions supports two programming models for Python. The way that you define your bindings depends on your chosen programming model.
26+
27+
# [v2](#tab/python-v2)
28+
The Python v2 programming model lets you define bindings using decorators directly in your Python function code. For more information, see the [Python developer guide](functions-reference-python.md?pivots=python-mode-decorators#programming-model).
29+
30+
# [v1](#tab/python-v1)
31+
The Python v1 programming model requires you to define bindings in a separate *function.json* file in the function folder. For more information, see the [Python developer guide](functions-reference-python.md?pivots=python-mode-configuration#programming-model).
32+
33+
---
34+
35+
This article supports both programming models.
36+
37+
> [!IMPORTANT]
38+
> The Python v2 programming model is currently in preview.
39+
::: zone-end
40+
2441
## Example
2542

2643
::: zone pivot="programming-language-csharp"
@@ -95,7 +112,27 @@ public void keepAlive(
95112
::: zone-end
96113
::: zone pivot="programming-language-javascript,programming-language-python,programming-language-powershell"
97114

98-
The following example shows a timer trigger binding in a *function.json* file and function code that uses the binding, where an instance representing the timer is passed to the function. The function writes a log indicating whether this function invocation is due to a missed schedule occurrence.
115+
The following example shows a timer trigger binding and function code that uses the binding, where an instance representing the timer is passed to the function. The function writes a log indicating whether this function invocation is due to a missed schedule occurrence. The example depends on whether you use the [v1 or v2 Python programming model](functions-reference-python.md).
116+
117+
# [v2](#tab/python-v2)
118+
119+
```python
120+
import datetime
121+
import logging
122+
import azure.functions as func
123+
app = func.FunctionApp()
124+
@app.function_name(name="mytimer")
125+
@app.schedule(schedule="0 */5 * * * *", arg_name="mytimer", run_on_startup=True,
126+
use_monitor=False)
127+
def test_function(mytimer: func.TimerRequest) -> None:
128+
utc_timestamp = datetime.datetime.utcnow().replace(
129+
tzinfo=datetime.timezone.utc).isoformat()
130+
if mytimer.past_due:
131+
logging.info('The timer is past due!')
132+
logging.info('Python timer trigger function ran at %s', utc_timestamp)
133+
```
134+
135+
# [v1](#tab/python-v1)
99136

100137
Here's the binding data in the *function.json* file:
101138

@@ -125,6 +162,8 @@ module.exports = async function (context, myTimer) {
125162
};
126163
```
127164

165+
---
166+
128167
::: zone-end
129168
::: zone pivot="programming-language-powershell"
130169

@@ -208,6 +247,24 @@ The following table explains the binding configuration properties for C# script
208247
---
209248

210249
::: zone-end
250+
251+
::: zone pivot="programming-language-python"
252+
## Decorators
253+
254+
_Applies only to the Python v2 programming model._
255+
256+
For Python v2 functions defined using a decorator, the following properties on the `schedule`:
257+
258+
| Property | Description |
259+
|-------------|-----------------------------|
260+
| `arg_name` | The name of the variable that represents the timer object in function code. |
261+
| `schedule` | A [CRON expression](#ncrontab-expressions) or a [TimeSpan](#timespan) value. A `TimeSpan` can be used only for a function app that runs on an App Service Plan. You can put the schedule expression in an app setting and set this property to the app setting name wrapped in **%** signs, as in this example: "%ScheduleAppSetting%". |
262+
| `run_on_startup` | If `true`, the function is invoked when the runtime starts. For example, the runtime starts when the function app wakes up after going idle due to inactivity. when the function app restarts due to function changes, and when the function app scales out. *Use with caution.* **runOnStartup** should rarely if ever be set to `true`, especially in production. |
263+
| `use_monitor` | Set to `true` or `false` to indicate whether the schedule should be monitored. Schedule monitoring persists schedule occurrences to aid in ensuring the schedule is maintained correctly even when function app instances restart. If not set explicitly, the default is `true` for schedules that have a recurrence interval greater than or equal to 1 minute. For schedules that trigger more than once per minute, the default is `false`. |
264+
265+
For Python functions defined by using *function.json*, see the [Configuration](#configuration) section.
266+
::: zone-end
267+
211268
::: zone pivot="programming-language-java"
212269
## Annotations
213270

@@ -221,6 +278,14 @@ The `@TimerTrigger` annotation on the function defines the `schedule` using the
221278
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python"
222279

223280
## Configuration
281+
::: zone-end
282+
283+
::: zone pivot="programming-language-python"
284+
_Applies only to the Python v1 programming model._
285+
286+
::: zone-end
287+
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python"
288+
224289

225290
The following table explains the binding configuration properties that you set in the *function.json* file.
226291

0 commit comments

Comments
 (0)