te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>python - Durable function retry settings - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Durable function retry settings - Stack Overflow

programmeradmin4浏览0评论

I wrote an Azure Function App with Durable Functions. While testing with a large dataset, I realized that the functionTimeout value was 10 mins. This caused some of the orchestrations to timeout. Thus began an indefinite number of retries of the failed orchestrations. I have increased the timeout setting to 1 hour 30 mins, but some of the old retries are still pending and therefore still running. I have tried stopping the function app and restarting it back up, but the execution of the orchestrations continued.

Two questions:

  1. Is there a manual way to stop the execution of the orchestrations other than stopping the function app?
  2. How do I set the number of retries to 0?

Here's the code for initiating the orchestrations:

import azure.functions as func
import azure.durable_functions as df 
import logging

app = df.DFApp(http_auth_level=func.AuthLevel.FUNCTION)

#HTTP triggered function invoked by the client
@app.route(route="orchestrators/{functionName}/{stateabbr}/{county}")
@app.durable_client_input(client_name="starter")
async def CleanMatchEnrichParcel(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    logging.info("CleanMatchEnrichParcel HTTP trigger function processed a request.")
    fname = req.route_params["functionName"]
    stateabbr = req.route_params["stateabbr"]
    county = req.route_params["county"]
    fparams = {"stateabbr": stateabbr, "county": county}
    instance_id = await starter.start_new(fname, None, fparams)
    logging.info(f"Started orchestration with ID = '{instance_id}'.")
    response = starter.create_check_status_response(req, instance_id)
    return(response)

@app.orchestration_trigger(context_name="context")
def orchestrator_function(context: df.DurableOrchestrationContext):
    #orchestration function code
    return(response)

I wrote an Azure Function App with Durable Functions. While testing with a large dataset, I realized that the functionTimeout value was 10 mins. This caused some of the orchestrations to timeout. Thus began an indefinite number of retries of the failed orchestrations. I have increased the timeout setting to 1 hour 30 mins, but some of the old retries are still pending and therefore still running. I have tried stopping the function app and restarting it back up, but the execution of the orchestrations continued.

Two questions:

  1. Is there a manual way to stop the execution of the orchestrations other than stopping the function app?
  2. How do I set the number of retries to 0?

Here's the code for initiating the orchestrations:

import azure.functions as func
import azure.durable_functions as df 
import logging

app = df.DFApp(http_auth_level=func.AuthLevel.FUNCTION)

#HTTP triggered function invoked by the client
@app.route(route="orchestrators/{functionName}/{stateabbr}/{county}")
@app.durable_client_input(client_name="starter")
async def CleanMatchEnrichParcel(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    logging.info("CleanMatchEnrichParcel HTTP trigger function processed a request.")
    fname = req.route_params["functionName"]
    stateabbr = req.route_params["stateabbr"]
    county = req.route_params["county"]
    fparams = {"stateabbr": stateabbr, "county": county}
    instance_id = await starter.start_new(fname, None, fparams)
    logging.info(f"Started orchestration with ID = '{instance_id}'.")
    response = starter.create_check_status_response(req, instance_id)
    return(response)

@app.orchestration_trigger(context_name="context")
def orchestrator_function(context: df.DurableOrchestrationContext):
    #orchestration function code
    return(response)
Share Improve this question edited 2 days ago anilcreates asked Feb 18 at 4:01 anilcreatesanilcreates 93 bronze badges 4
  • Are you okay with terminating all orchestrations, or just pausing execution for now – Kraigolas Commented Feb 18 at 4:13
  • I am fine with terminating all the orchestrations – anilcreates Commented Feb 18 at 4:23
  • You can terminate the orchestration using function core tools command func durable terminate --id <orchestration_id> --reason <reason>. Refer Msdoc – Pravallika KV Commented 2 days ago
  • I am executing the function app serverless in Azure. This command requires terminal access. – anilcreates Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 0
  1. Is there a manual way to stop the execution of the orchestrations other than stopping the function app?

You can stop the running Orchestration by suspending the Orchestration, refer MSDOC

suspend_reason = "Found a bug"
client.suspend(instance_id, suspend_reason)

Code:

myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@myApp.route(route="orchestrators/{functionName}")
@myApp.durable_client_input(client_name="client")
async def http_start(req: func.HttpRequest, client):
    function_name = req.route_params.get('functionName')
    instance_id = await client.start_new(function_name)
    response = client.create_check_status_response(req, instance_id)
    await client.suspend(instance_id, "found a bug")
    logging.info("Orchestration suspended")
    return response

Console response:

Functions:

        http_start:  http://localhost:7071/api/orchestrators/{functionName}

        hello: activityTrigger

        hello_orchestrator: orchestrationTrigger

For detailed output, run func with --verbose flag.
[2025-02-18T07:55:19.194Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2025-02-18T07:55:50.392Z] Executing 'Functions.http_start' (Reason='This function was programmatically called via the host APIs.', Id=05a6a228-0dfb-4dcd-8c91-29da78ed0a1e)

[2025-02-18T07:55:50.760Z] Orchestration suspended

[2025-02-18T07:55:50.960Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=07f199d9-fd10-422b-a66e-e84677011a30)
[2025-02-18T07:55:50.966Z] Executed 'Functions.http_start' (Succeeded, Id=05a6a228-0dfb-4dcd-8c91-29da78ed0a1e, Duration=607ms)
[2025-02-18T07:55:51.054Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=07f199d9-fd10-422b-a66e-e84677011a30, Duration=110ms)
[2025-02-18T07:55:51.126Z] Executing 'Functions.hello' (Reason='(null)', Id=31e72fb9-ce64-4983-a931-8ceb9b1be8c1)
[2025-02-18T07:55:51.133Z] Executed 'Functions.hello' (Succeeded, Id=31e72fb9-ce64-4983-a931-8ceb9b1be8c1, Duration=9ms)
[2025-02-18T07:55:51.154Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=690cd49d-2765-41e0-bb43-e8b85c51f18a)
[2025-02-18T07:55:51.167Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=690cd49d-2765-41e0-bb43-e8b85c51f18a, Duration=15ms)
[2025-02-18T07:55:51.201Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=2d51e367-b295-45b4-ace4-a24dd1c5615e)
[2025-02-18T07:55:51.210Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=2d51e367-b295-45b4-ace4-a24dd1c5615e, Duration=9ms)

Orchestration Status can be seen as below:

You can also terminate the Orchestration by running the terminatePostURI of the function:

[2025-02-18T08:03:25.173Z] 523f442ed0574d3dab2f2d0226a27ce7: Function 'hello_orchestrator (Orchestrator)' was terminated. 
Reason: found a bug. State: Terminated. RuntimeStatus: Terminated. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.13.2. SequenceNumber: 12.
[2025-02-18T08:03:25.233Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=95c9b9a7-5728-4ad5-ab35-439a6d377714)
[2025-02-18T08:03:25.242Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=95c9b9a7-5728-4ad5-ab35-439a6d377714, Duration=10ms)
  1. How do I set the number of retries to 0?

Set max_number_of_attempts=1, refer MSDOC.

first_retry_interval_in_milliseconds  =  5000
max_number_of_attempts  =  1
retry_options = df.RetryOptions(first_retry_interval_in_milliseconds, max_number_of_attempts)

Code:

# Orchestrator
@myApp.orchestration_trigger(context_name="context")
def hello_orchestrator(context: df.DurableOrchestrationContext):
    first_retry_interval_in_milliseconds = 5000
    max_number_of_attempts = 1

    retry_options = df.RetryOptions(first_retry_interval_in_milliseconds, max_number_of_attempts)
    result = yield context.call_activity_with_retry('hello', retry_options)
    result1 = yield context.call_activity("hello", "Seattle")
    result2 = yield context.call_activity("hello", "Tokyo")
    result3 = yield context.call_activity("hello", "London")

    return [ result1, result2, result3]
发布评论

评论列表(0)

  1. 暂无评论