1

I have a GitHub repository with some .py scripts. What would be the steps to follow to get them running in Azure through a cron scheduler?

3
  • 2
    Have you looked at the docs ? azure.microsoft.com/en-gb/services/functions & learn.microsoft.com/en-us/azure/azure-functions/… Commented Mar 9, 2021 at 15:19
  • 1
    @Manakin Is this OS dependent? The Azure I'm referring to is has Linux running on it. Also, is it possible at all to link it to my repository? Commented Mar 9, 2021 at 15:35
  • 1
    What do you mean by Azure, the portal or a virtual machine? a function is a severless app - meaning you don't need to provision any specific hardware for it, you just need to deploy your code and then it can run and you pay for your compute on demand. Commented Mar 9, 2021 at 15:39

1 Answer 1

3

My recommendation would be to use Azure Python Functions with a time trigger binding and call your Python modules from there.

A simplistic sample project structure could look like this

├── function-app/
│   ├── __init__.py
│   └── function.json
└── shared/
    └── your_module.py

where __init__.py contains the Azure Function wrapper code that gets executed according to the cron schedule

from __app__.shared.your_module import your_function

def main(mytimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

    # call your_function() here

and function.json contains among others the cron schedule expression, in this example running every 6 hours.

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 */6 * * *"
    }
  ]
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your input. Is there any way I could read the latest version of my .py from my GitHub repository?
You could create a Github Action that gets triggered every time you push changes in your repository. See learn.microsoft.com/en-us/azure/azure-functions/…

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.