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
-
2Have you looked at the docs ? azure.microsoft.com/en-gb/services/functions & learn.microsoft.com/en-us/azure/azure-functions/…Umar.H– Umar.H2021-03-09 15:19:43 +00:00Commented 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?Javi Torre– Javi Torre2021-03-09 15:35:06 +00:00Commented Mar 9, 2021 at 15:35
-
1What 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.Umar.H– Umar.H2021-03-09 15:39:53 +00:00Commented Mar 9, 2021 at 15:39
Add a comment
|
1 Answer
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 * * *"
}
]
}
2 Comments
Javi Torre
Thanks for your input. Is there any way I could read the latest version of my .py from my GitHub repository?
Christian Vorhemus
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/…