You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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}')
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
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.
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.
Activity
lukaszsocha2 commentedon Jul 12, 2023
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 fieldsource, 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 haveparentfield, 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:
Best,
@lukaszsocha2
annie0467 commentedon Jul 14, 2023
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
And I confirmed that there is not authorization problem in the folder path I give
any suggestions?
mhagmajer commentedon Jul 24, 2023
Hi @annie0467, can you share your monitoring code that errors after a few minutes? We'll try to reproduce on our side
stale commentedon Aug 23, 2023
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.
stale commentedon Sep 2, 2023
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.