Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear how to resume iterating with PageIterator if the callback returns False #688

Open
jasonjoh opened this issue Sep 23, 2024 · 2 comments
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned

Comments

@jasonjoh
Copy link
Member

In other SDKs, the iterator class typically has a Resume method to restart the iteration where it left off, and a corresponding State property to check if the iterator has completed or not. For example, in .NET:

var pageIterator = PageIterator<Message, MessageCollectionResponse>
    .CreatePageIterator(
        graphClient,
        messages,
        (msg) =>
        {
            Console.WriteLine(msg.Subject);
            count++;
            // If we've iterated over the limit,
            // stop the iteration by returning false
            return count < pauseAfter;
        });

await pageIterator.IterateAsync();

while (pageIterator.State != PagingState.Complete)
{
    Console.WriteLine("Iteration paused for 5 seconds...");
    await Task.Delay(5000);
    // Reset count
    count = 0;
    await pageIterator.ResumeAsync();
}

Is there a way to do this in this SDK?

@jasonjoh jasonjoh added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Sep 23, 2024
@jasonjoh
Copy link
Member Author

For context, this is so I can add Python snippets to this documentation: https://learn.microsoft.com/en-us/graph/sdks/paging

@jasonjoh
Copy link
Member Author

I've done some experimentation, and I found that after a pause, I can just call iterate again to start back up from where it left off. However, there's no good way that I can see for my code to detect that it should stop calling iterate. Once the iterator gets to the last page from the server, my code just continually iterates over that page.

while True:
    # The callback here returns false after iterating over 25 messages
    await page_iterator.iterate(Paging.message_callback_with_pause)

    # Ideally I could test something here and break out of the loop

    time.sleep(5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned
Projects
None yet
Development

No branches or pull requests

1 participant