Skip to content

Monitor events in subfolders recursively #828

Closed

Description

@annie0467

Given a single folder, Is there any way to keep monitoring all of its subfolders for events(ex: ITEM_UPLOAD, ITEM_DOWNLOAD, etc) and associate it with the specific folder name?

For ex: hierarchy is as follows
/ Main_Folder
-> A
-> B
-> C

There might be more folders in A, B, C
I need to track events in each subfolder folder

I wish to use generate_events_with_long_polling()

I have tried creating a monitoring thread on each single folder, but I run into unexpected issues after sometime.

Activity

  1. lukaszsocha2 commented on Jul 12, 2023

    @lukaszsocha2
    Contributor

    Hi @annie0467,
    by default generate_events_with_long_polling() provides ALL events for the authenticated user. So if an action takes place in any directory, you will get an event for it. Event has field source, which allow to get more details about event source. It could be one of: File / Folder / User / Event source object. See Event object documentation here. If the event source is File, Folder or Event source, it will have parent field, so you can filter out events happening in a specific folder (or a set of folders).
    You can use this code snippet to print name of the folder, in which the event takes place:

    events = client.events().generate_events_with_long_polling()
    for event in events:
        event_source = event.source
        if event_source.parent:
            print(f'Got {event.event_type} event in folder: {event_source.parent.name}')
    

    Best,
    @lukaszsocha2

  2. annie0467 commented on Jul 14, 2023

    @annie0467
    Author

    Thanks for your reply @lukaszsocha2
    I was using the exact same code with tweaks of my folder id matching
    but I now have figured how to track events in all subfolders using this same code.

    My only concern is that even after exception handling, the monitoring code get errors unexpectedly say after a few minutes or so

        raise BoxAPIException(
    boxsdk.exception.BoxAPIException: Message: Authorization Failed
    Status: 404
    Code: not_found
    

    And I confirmed that there is not authorization problem in the folder path I give
    any suggestions?

  3. mhagmajer commented on Jul 24, 2023

    @mhagmajer
    Contributor

    Hi @annie0467, can you share your monitoring code that errors after a few minutes? We'll try to reproduce on our side

  4. stale commented on Aug 23, 2023

    @stale

    This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.

  5. stale commented on Sep 2, 2023

    @stale

    This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box Python SDK and feel free to open another PR/issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions