-1

What would be the best approach to run scheduled python script on azure which is making some calculation and storing result as CSV in Azure Blobs

2 Answers 2

4

The best solution to this problem is to create an Azure function with a timer trigger. You can configure the timer to execute as often as you want.

Here's an example for the timer configuration, which will execute the script timerfunc.py every working day at 12PM:

{
  "scriptFile": "timerfunc.py",
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 12 * * 1-5"
    }
  ]
}

an example for timerfunc.py:

import datetime
import logging

import azure.functions as func

def main(mytimer: func.TimerRequest) -> None:
    logging.info('Function executed!')

You can find more examples of Python code, as well as information on how to configure the timer, at the following documentation page https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python

Sign up to request clarification or add additional context in comments.

Comments

2

Update: The Python v2 programming model lets you define bindings using decorators directly in your Python function code.

Same example as above, the script will be triggered every working day at 12PM:

import logging
import azure.functions as func

app = func.FunctionApp()

@app.schedule(schedule="0 0 12 * * 1-5", arg_name="myTimer", run_on_startup=True,
              use_monitor=False)
def test_my_timer(myTimer: func.TimerRequest) -> None:
    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function executed.')

Ref: Azure Function Example v2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.