1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Azure Function with Blob Trigger Running with InputStream but not with BlobClient...

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to get a blob-triggered Azure Function to work. I got the samples to run, and am all set up with my local development AzureWebJobsStorage connection string set up to use Azurite. I am testing by adding a file using Azure Storage Explorer.

    This function triggers and my code is run:

    @app.blob_trigger(arg_name="myblob", path="inbox",
    connection="AzureWebJobsStorage")
    def BlobTriggerTest4(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob. "
    f"Name: {myblob.name}, "
    f"Blob Size: {myblob.length} bytes")


    Log output in the VS Code terminal (size shows as zero in this code from the MS sample, which is fine, because stream has not yet been read):

    [2024-09-13T09:15:37.534Z] Host lock lease acquired by instance ID '000000000000000000000000FF46044C'.
    [2024-09-13T09:15:45.228Z] Executing 'Functions.BlobTriggerTest4' (Reason='New blob detected(LogsAndContainerScan): inbox/test.txt', Id=2bf0477b-06e1-4af3-af64-285dd0d65d20)
    [2024-09-13T09:15:45.230Z] Trigger Details: MessageId: e46320bd-d339-49a7-af17-2be2def490d1, DequeueCount: 1, InsertedOn: 2024-09-13T09:15:45.000+00:00, BlobCreated: 2024-09-13T09:15:44.000+00:00, BlobLastModified: 2024-09-13T09:15:44.000+00:00

    [2024-09-13T09:15:45.300Z] Python blob trigger function processed blob. Name: inbox/test.txt, Blob Size: None bytes

    [2024-09-13T09:15:45.316Z] Executed 'Functions.BlobTriggerTest4' (Succeeded, Id=2bf0477b-06e1-4af3-af64-285dd0d65d20, Duration=140ms)


    When I change it to use BlobClient, however, the function triggers buy my code isn't run! I want to use BlobClient so I can easily delete the blob once I have processed it.

    @app.blob_trigger(arg_name="myblob", path="inbox",
    connection="AzureWebJobsStorage")
    def BlobTriggerTest5(myblob: blob.BlobClient):
    logging.info(
    f"Python blob trigger function processed blob. Properties: {myblob.get_blob_properties()}. Blob content head: {myblob.download_blob().read(size = 1)}"
    )


    Here is the output. I get the boilerplate framework output but my own logging code doesn't run:

    [2024-09-13T09:17:58.634Z] Host lock lease acquired by instance ID '000000000000000000000000FF46044C'.
    [2024-09-13T09:18:02.117Z] Executing 'Functions.BlobTriggerTest5' (Reason='New blob detected(LogsAndContainerScan): inbox/test.txt', Id=af20f729-9414-4531-b22a-e75d9031b225)
    [2024-09-13T09:18:02.120Z] Trigger Details: MessageId: 548b4b12-5af0-4b5e-b424-2fe7222c4908, DequeueCount: 1, InsertedOn: 2024-09-13T09:18:02.000+00:00, BlobCreated: 2024-09-13T09:18:00.000+00:00, BlobLastModified: 2024-09-13T09:18:00.000+00:00


    Note that in this case with BlobClient I am not even getting the usual "Executed 'Functions.BlobTriggerTest5'" terminating message in the logs, almost as if the function has somehow got "stuck" right after triggering.

    I had more code in these test functions previously, and none of it was running. I cut these examples down to more clearly demonstrate the problem.

    I tried recreating the function from scratch in case the previous name had somehow been bound to the earlier implementation, etc. I can just switch back and forth between these two functions (only having one uncommented at a time since they trigger on the same blob path), and with the first using InputStream my function code runs and with the second using BlobClient it does not (despite the function showing it has been triggered!).

    Can anyone suggest what I might be doing wrong or what is happening here? Many thanks in advance.

    Continue reading...

Compartilhe esta Página