We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
RobinHarveyIW
4 years agoExplorer | Level 4
Update latency for files_list_folder cursor
I'm trialing the simple polling method outlined here, and AFAICS it's taking a few hours for changes in my DB folders / files to be reflected in the results of files_list_folder and files_list_folder_continue. Is this expected? I was hoping that updates would be visible in API results in the seconds-to-minutes range, do I need to use a different API to get near this?
Here's my code, in case I've messed anything up 🙂
def poll_loop(client: DropboxClient,
db_path: str,
poll_freq: int,
db_cursor: str = None):
if db_cursor is None:
list_result = client.files_list_folder(path=db_path, recursive=True)
else:
list_result = client.files_list_folder_continue(db_cursor)
while True:
log.info("scan files from cursor %s", list_result.cursor)
while list_result.has_more:
for entry in list_result.entries:
log.info("scanned path: %s", entry.path_display)
list_result = client.files_list_folder_continue(list_result.cursor)
log.info("new cursor %s", list_result.cursor)
if poll_freq == 0:
return
else:
log.info("pause for %d seconds before next poll", poll_freq)
time.sleep(poll_freq)
list_result = client.files_list_folder_continue(list_result.cursor)
log.info("new cursor %s", list_result.cursor)
1 Reply
- RobinHarveyIW4 years agoExplorer | Level 4
I figured out what the issue here was - it's the way my code was handling results pages and cursors. I switched the loop control checks around a bit and it all started working fine:
def poll_loop(client: DropboxClient, db_path: str, poll_freq: int, db_cursor: str = None): if db_cursor is None: list_result = client.files_list_folder(path=db_path, recursive=True) else: list_result = client.files_list_folder_continue(db_cursor) while True: log.info("scan files from cursor %s", list_result.cursor) while list_result.entries: for entry in list_result.entries: log.info("scanned path: %s", entry.path_display) if list_result.has_more: list_result = client.files_list_folder_continue(list_result.cursor) log.debug("new cursor %s", list_result.cursor) else: log.debug("cursor is exhausted") break if poll_freq == 0: log.info("final cursor: %s", list_result.cursor) return else: log.debug("pause for %d seconds before next poll", poll_freq) log.info("latest cursor: %s", list_result.cursor) time.sleep(poll_freq) list_result = client.files_list_folder_continue(list_result.cursor)
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 2 hours ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!