azure-functions-sql-extension icon indicating copy to clipboard operation
azure-functions-sql-extension copied to clipboard

Add SQL template for Python v2

Open lucyzhang929 opened this issue 1 year ago • 5 comments

Add template here: https://github.com/Azure/azure-functions-templates/tree/dev/Functions.Templates/Templates-v2

lucyzhang929 avatar Apr 03 '24 20:04 lucyzhang929

Is it possible to add multiple rows to the database in one go?

LouisDeconinck avatar Apr 30 '24 21:04 LouisDeconinck

Yes, in Python you can use SqlRowList to add multiple rows. See this sample: https://github.com/Azure/azure-functions-sql-extension/blob/3a5971284fc6bb6dc0d16e4d10f159220de4e9a2/samples/samples-python/AddProductsArray/init.py#L16

lucyzhang929 avatar Apr 30 '24 22:04 lucyzhang929

@LouisDeconinck, this seems like a functions error, not specific to SQL Bindings. Could you file an issue in the Azure Functions Host repository?

lucyzhang929 avatar May 01 '24 15:05 lucyzhang929

@lucyzhang929 I'm running into another issue. Getting the following error: Database on server is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '{C16638E0-26B4-4AB7-B831-19F334051195}'.

Is there anyway how I can detect that the database will not be available and retry writing another time?

I have the following code, but this doesn't work as I believe that the .set() happens asynchronously after the function has already ended.

        max_retries = 10
        retries = 0

        while retries < max_retries:
            try:
                r.set(rows_sql)
                
                total_time = time.time() - start_time

                logging.info(f"End of scraping. Scraped {len(rows)} groups in {total_time}.")
                break

            except Exception as e:
                logging.error(f"An error occurred: {str(e)}")
                retries += 1
                if retries < max_retries:
                    logging.info(f"Retrying after 30 seconds... (retry {retries}/{max_retries})")
                    time.sleep(30)
                else:
                    logging.error(f"An error occurred: {str(e)}")

LouisDeconinck avatar May 01 '24 18:05 LouisDeconinck

@LouisDeconinck Can you create a separate issue for your question please? https://github.com/Azure/azure-functions-sql-extension/issues/new/choose Thank you!

lucyzhang929 avatar May 01 '24 20:05 lucyzhang929