Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SQL template for Python v2 #1063

Open
lucyzhang929 opened this issue Apr 3, 2024 · 5 comments
Open

Add SQL template for Python v2 #1063

lucyzhang929 opened this issue Apr 3, 2024 · 5 comments

Comments

@lucyzhang929
Copy link
Contributor

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

@LouisDeconinck
Copy link

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

@lucyzhang929
Copy link
Contributor Author

Yes, in Python you can use SqlRowList to add multiple rows. See this sample:

rows = func.SqlRowList(map(lambda r: func.SqlRow.from_dict(r), body))

@lucyzhang929
Copy link
Contributor Author

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

@LouisDeconinck
Copy link

@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)}")

@lucyzhang929
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants