Giter VIP home page Giter VIP logo

Comments (5)

nytian avatar nytian commented on August 28, 2024

Hi, @Goldziher Do you have durable functions app that can help me check the logs or any samples that can help me reproduce at my local end?

from azure-functions-durable-python.

Goldziher avatar Goldziher commented on August 28, 2024

Hi, @Goldziher Do you have durable functions app that can help me check the logs or any samples that can help me reproduce at my local end?

I'm afraid only closed source

from azure-functions-durable-python.

nytian avatar nytian commented on August 28, 2024

No worries. Can you help me specify the scenario using with context.signal_entity? Like calling this in a sub-orchestrator and thus make it never finish.

from azure-functions-durable-python.

Goldziher avatar Goldziher commented on August 28, 2024

No worries. Can you help me specify the scenario using with context.signal_entity? Like calling this in a sub-orchestrator and thus make it never finish.

Certainly. I'll post some snippets later

from azure-functions-durable-python.

Goldziher avatar Goldziher commented on August 28, 2024

Ok, here is some code that works as is, but if you change call_activity to signal_activity it blocks indefinitely:

def file_download_orchestrator(
    context: DurableOrchestrationContext,
) -> Generator[TaskBase, None, NotificationAttachment | None]:
    """This is a sub-orchestrator function that downloads a file from Google Drive, saves it to blob storage and updates
    the state of the durable entity.

    Args:
        context: The durable orchestration context.

    Returns:
        A generator.
    """
    directory_path, file_datum = cast(tuple[str, FileData], context.get_input())
    # 1. download file
    file_blob_or_error = cast(
        FileBlob | NotificationAttachment,
        (yield context.call_activity(FILE_DOWNLOAD_ACTIVITY, (directory_path, file_datum))),
    )

    if not all(k in file_blob_or_error for k in FileBlob.__annotations__):
        logger.warning("File %s download failed. Skipping file persistence and state update.", file_datum["id"])
        return cast(NotificationAttachment, file_blob_or_error)

    file_blob = cast(FileBlob, file_blob_or_error)

    # 2. save file to blob storage
    yield context.call_activity(SAVE_BLOB_DATA_ACTIVITY, file_blob)
    # 3. update state
    # note: we are using context.call_entity rather than context.signal_entity, because signal_entity causes blocking
    yield context.signal_entity(
        EntityId(STORE_HANDLER_ENTITY, file_blob["drive_id"]),
        EntityStateOperation.SET.value,
        (file_blob["file_id"], file_blob["modified_time"]),
    )
    logger.info("File %s was downloaded and persisted successfully", file_blob["file_id"])
    return None

And this is the entity handler:

from enum import StrEnum
from typing import cast

from azure.durable_functions import DurableEntityContext


class EntityStateOperation(StrEnum):
    """An enum for the durable entity state operations."""

    GET = "get"
    DEL = "del"
    SET = "set"


def store_handler(context: DurableEntityContext) -> None:
    """Handler for the durable entity. A durable entity is created for each drive ID.

    Args:
        context: The durable entity context, injected by the runtime.

    Returns:
        None
    """
    state = context.get_state(dict)
    match context.operation_name:
        case EntityStateOperation.GET.value:
            context.set_result(state)
        case EntityStateOperation.DEL.value:
            state.pop(cast(str, context.get_input()), None)
            context.set_state(state)
        case EntityStateOperation.SET.value:
            file_id, modified_date = cast(tuple[str, int], context.get_input())
            context.set_state({**state, file_id: modified_date})
        case _:
            # this should never happen
            raise ValueError(f"Invalid operation: {context.operation_name}")

from azure-functions-durable-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.