У меня 2 функции,
- Триггер таймера
- Триггер Http
Теперь триггер HTTP работает нормально, более 20 минут, выполняет задание и успешно завершается.
В то же время функция таймера все еще должна работать, но ее время истекает ровно через 4:02 минуты:
Код: Выделить всё
Failed to process table CALENDAR. Response: b'504.0 GatewayTimeout'
Вот как выглядит функция таймера:
TimerFunction.py
Код: Выделить всё
import logging
import os
import sys
import azure.functions as func
import requests
import json
import datetime
import time
from shared.db import get_all_p6_table_names, insert_to_batch_detail
# Add the shared folder to the system path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'shared')))
from shared.db import get_all_table_names, insert_to_batch_detail
# Set the function endpoint URL (update with the actual endpoint URL)
COPY_AND_MERGE_ENDPOINT_URL = os.getenv("COPY_AND_MERGE_ENDPOINT_URL")
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
try:
# Fetch all table names
tableDetails = get_all_table_names()
logging.info(f"All Tables: {tableDetails}")
if not tableDetails:
logging.warning("No tables found in dbo.TableDetailsSummary")
# Call CopyAndMergeDataFromP6ApiToDb for each table
for table in tableDetails:
logging.info(f"Table: {table[0]}, Project Ref field: {table[1]}")
response = call_copy_and_merge_endpoint(table[0], table[1])
if response.status_code != 200:
logging.error(f"Failed to process table {table[0]}. Response: {response.content}")
return
logging.info("All tables processed successfully.")
except Exception as e:
logging.error(f"Error: {str(e)}")
finally:
# Ensure that logging is flushed and closed after the function finishes
logging.shutdown()
def call_copy_and_merge_endpoint(tableName, projRefField):
batch_id = insert_to_batch_detail(tableName)
payload = {
'tableName': tableName,
'projRefField': projRefField,
'batchId': batch_id
}
headers = {'Content-Type': 'application/json'}
response = requests.post(COPY_AND_MERGE_ENDPOINT_URL, headers=headers, data=json.dumps(payload))
return response
Также мой файл host.json выглядит так :
Код: Выделить всё
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
},
"functionTimeout": "07:00:00"
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... r-402-mins