UNPKG

2.73 kBTypeScriptView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4import { FunctionOptions, FunctionResult, FunctionTrigger, RetryOptions } from './index';
5import { InvocationContext } from './InvocationContext';
6
7export type TimerHandler = (myTimer: Timer, context: InvocationContext) => FunctionResult;
8
9export interface TimerFunctionOptions extends TimerTriggerOptions, Partial<FunctionOptions> {
10 handler: TimerHandler;
11
12 trigger?: TimerTrigger;
13
14 /**
15 * An optional retry policy to rerun a failed execution until either successful completion occurs or the maximum number of retries is reached.
16 * Learn more [here](https://learn.microsoft.com/azure/azure-functions/functions-bindings-error-pages)
17 */
18 retry?: RetryOptions;
19}
20
21export interface TimerTriggerOptions {
22 /**
23 * A [cron expression](https://docs.microsoft.com/azure/azure-functions/functions-bindings-timer?pivots=programming-language-javascript#ncrontab-expressions) of the format '{second} {minute} {hour} {day} {month} {day of week}' to specify the schedule
24 */
25 schedule: string;
26
27 /**
28 * If `true`, the function is invoked when the runtime starts.
29 * 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.
30 * _Use with caution_. runOnStartup should rarely if ever be set to `true`, especially in production.
31 */
32 runOnStartup?: boolean;
33
34 /**
35 * When true, schedule will be persisted to aid in maintaining the correct schedule even through restarts. Defaults to true for schedules with interval >= 1 minute
36 */
37 useMonitor?: boolean;
38}
39
40export type TimerTrigger = FunctionTrigger & TimerTriggerOptions;
41
42/**
43 * Timer schedule information. Provided to your function when using a timer binding.
44 */
45export interface Timer {
46 /**
47 * Whether this timer invocation is due to a missed schedule occurrence.
48 */
49 isPastDue: boolean;
50 schedule: {
51 /**
52 * Whether intervals between invocations should account for DST.
53 */
54 adjustForDST: boolean;
55 };
56 scheduleStatus: {
57 /**
58 * The last recorded schedule occurrence. Date ISO string.
59 */
60 last: string;
61 /**
62 * The expected next schedule occurrence. Date ISO string.
63 */
64 next: string;
65 /**
66 * The last time this record was updated. This is used to re-calculate `next` with the current schedule after a host restart. Date ISO string.
67 */
68 lastUpdated: string;
69 };
70}