Absolutely - look at the Job functionality, has all of this built in, including the ability to track the index of where you're up to.
Start with XF\Job\Manager
and look at all the job classes in XF\Job\*
for examples.
You can even have the job delayed to start at a later time - ideal to handle time based API limits.