@11-4688 Thanks for reaching out.
Please refer to orchestrator function and activity function document for more details.
Create an orchestrator function that will handle the workflow. The orchestrator function will call the search function and wait for the results to be returned. If the search function takes longer than the default timeout (which is 10 minutes), the orchestrator function will automatically checkpoint its state and return a response indicating that the operation is still in progress.
import azure.functions as func
import json
import os
from typing import List
from google_search import search
from azure.durable_functions import (
durable_task,
TaskOrchestrationContext,
TaskActivityContext
)
@durable_task
def search_orchestrator(context: TaskOrchestrationContext, search_terms: str, num_results: int, country_code: str) -> List[dict]:
api_key = os.getenv('apikey')
cse_id = os.getenv('cseid')
# Call the search function with the provided arguments
df = yield context.call_activity('search_activity', search_terms, num_results, country_code, api_key, cse_id)
# Convert DataFrame to a list of dictionaries
response_data = df.to_dict(orient='records')
# Serialize the response data to JSON
response_json = json.dumps(response_data)
# Return the response as a JSON array
return response_json
Create an activity function that will perform the search operation. The activity function will be called by the orchestrator function and will perform the search operation. If the search operation takes longer than the default timeout, the activity function will automatically checkpoint its state and return a response indicating that the operation is still in progress.
@durable_task
def search_activity(context: TaskActivityContext, search_terms: str, num_results: int, country_code: str, api_key: str, cse_id: str) -> pd.DataFrame:
# Call the search function with the provided arguments
df = search(search_terms=search_terms,
num_results, country_code=country_code, api_key=api_key, cse_id=cse_id)
# Return the search results as a Pandas DataFrame
return df
Now Create a client function that will trigger the orchestrator function. The client function will be called by the HTTP trigger and will start the search workflow by calling the orchestrator function.
Note: The above is only for reference and please test and modify as per your input as this is based on your existing function. I couldn't test with the input value as per you are passing.