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

Functions silently failing #516

Open
rokcarl opened this issue Jul 24, 2024 · 0 comments
Open

Functions silently failing #516

rokcarl opened this issue Jul 24, 2024 · 0 comments
Assignees
Labels
P2 Priority 2

Comments

@rokcarl
Copy link

rokcarl commented Jul 24, 2024

I have three issues here, but let's start with this one before uncovering the others.

When running the orchestration, seemingly not all things run as they should, but I get no exceptions or errors in the output.
My code is a bit unconventional because I'm trying to implement complex flows with durable functions, so I want to create functions dynamically.

function_app.py
import logging
import typing

from functools import partial

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

from pydantic import BaseModel

logger = logging.getLogger("azure.core.pipeline.policies.http_logging_policy")
logger.setLevel(logging.WARNING)

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


class ActivityFunction(BaseModel):
    function: typing.Callable

def activity_baseline(f, *args, **kwargs):
    print(f"Running {f.__name__}")
    try:
        result = f(*args, **kwargs)
    except Exception:
        result = f"Failed activity {f.__name__}"
    return result


def s2a1(name: str) -> dict:
    print(f"[TASK] s2a1: hello {name}.")
    return {"activity": "s2a1", "name": name}


@app.route(route="t1")
@app.durable_client_input(client_name="client")
async def t1_http(req: func.HttpRequest, client: df.DurableOrchestrationClient) -> func.HttpResponse:
    error = bool(req.params.get("error") or False)
    instance_id = await client.start_new("t1", client_input={"error": error})
    return client.create_check_status_response(req, instance_id)


@app.orchestration_trigger(context_name="context")
def t1(context: df.DurableOrchestrationContext):
    logging.info("[orchestrator] Running")
    data = context.get_input() or {}
    activity = ActivityFunction(function=s2a1)
    azure_f = partial(activity_baseline, activity.function)
    azure_f.__name__ = activity.function.__name__
    app.activity_trigger(input_name="inputs", activity=activity.function.__name__)(azure_f)
    tasks = [context.call_activity(activity.function.__name__, data)]
    logging.info("[tasks] running all tasks")
    results = yield context.task_all(tasks)
    logging.info("[tasks] results:")
    logging.info(results.__repr__())
    logging.info(results)
    logging.info("[orchestrator] finished")
    return results
requirements.txt
azure-common==1.1.28
azure-core==1.29.5
azure-functions==1.20.0
azure-functions-durable==1.2.9
azure-identity==1.14.1
azure-storage-blob==12.18.3
pydantic==2.7.2
log no. 1
[2024-07-24T09:24:00.599Z] Worker process started and initialized.
[2024-07-24T09:24:05.664Z] Host lock lease acquired by instance ID '0000000000000000000000001DA5AB02'.
[2024-07-24T09:24:07.916Z] Executing 'Functions.t1_http' (Reason='This function was programmatically called via the host APIs.', Id=e502f88a-64f6-48cb-bdba-e46c326c6ef0)
[2024-07-24T09:24:08.195Z] Executed 'Functions.t1_http' (Succeeded, Id=e502f88a-64f6-48cb-bdba-e46c326c6ef0, Duration=292ms)
[2024-07-24T09:24:08.343Z] Executing 'Functions.t1' (Reason='(null)', Id=4a587992-146f-461c-85ea-9c8140a9cb43)
[2024-07-24T09:24:08.392Z] [tasks] running all tasks
[2024-07-24T09:24:08.392Z] [orchestrator] Running
[2024-07-24T09:24:08.421Z] Executed 'Functions.t1' (Succeeded, Id=4a587992-146f-461c-85ea-9c8140a9cb43, Duration=89ms)
log no. 1
[2024-07-24T09:30:24.166Z] Executing 'Functions.t1_http' (Reason='This function was programmatically called via the host APIs.', Id=0c5d0e54-1934-474c-bf9b-270e9da42b6d)
[2024-07-24T09:30:24.254Z] Executed 'Functions.t1_http' (Succeeded, Id=0c5d0e54-1934-474c-bf9b-270e9da42b6d, Duration=93ms)
[2024-07-24T09:30:24.267Z] Executing 'Functions.t1' (Reason='(null)', Id=737248a6-c111-4cac-a5df-e316371f679d)
[2024-07-24T09:30:24.283Z] [orchestrator] Running
[2024-07-24T09:30:24.283Z] [tasks] running all tasks
[2024-07-24T09:30:24.293Z] Executed 'Functions.t1' (Succeeded, Id=737248a6-c111-4cac-a5df-e316371f679d, Duration=29ms)

There are two things wrong in the above logs. First off, the logs coming out are not deterministic or at least there's some race condition happening as one the [orchestrator] and the [tasks] log order is mixed up between no. 1 and 2. I don't see how this could happen as this is run in the same thread.

But more importantly, the logging commands below don't run and there's no exception. So I'm wondering, does the code run and the logs don't appear in my console or, what I think is happening, is the orchestrator doesn't fully run because there are errors in the activity functions and something breaks.

🤔 Expected behavior
Either I get an exception or all the code runs.

Steps to reproduce
Run func start locally on my code and visit http://localhost:7071/api/t1, then check the logs.

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

No branches or pull requests

3 participants