2

Ive written a python script to get information from an API, do some Pandas wrangling and format it to insert into my azure postgres instance with SQLAlchemy. I'd like to be able to run this every night, obviously automated, but I can't find anything that actual shows details about how to incorporate azure functions or how to incorporate my script into azure functions.

Any help would be great, but I'd really appreciate resources that you have found helpful.

1
  • 1
    Did you get this answered? Do you have step by step on how I can integrate my code in an azure function. Have been on it for days. Your help will be appreciated. Commented Oct 28, 2020 at 21:38

1 Answer 1

2

The easiest way would be by the usage of Time trigger, then use Cron format to specify the desired time for the execution.

Here's a sample:

function.json

{
    "name": "mytimer",
    "type": "timerTrigger",
    "direction": "in",
    "schedule": "0 */5 * * * *"
}

code:

import datetime
import logging

import azure.functions as func


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

    if mytimer.past_due:
        logging.info('The timer is past due!')

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

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python#example

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

7 Comments

I appreciate it. That's about as far as I have gotten. Do I import my functions and just add them under the "if my.timer.past_due:" statement?
yes, just implement the logic over there and it should get executed according to the cron you'll specify.
Ok, thanks I've gotten that. What's the purpose of the blob that is created as well, do you need to upload the project to the blob to the function can access it? That would make sense.
I am not sure which blob you're talking about, but probably it's the "state", or in another words, when the next executions should happen
I'd recommend you to start with the azure functions, then add your code.
|

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.