Use Tag Change scripts for this. I would write the bulk of the logic in app.* Python modules and call them in Gateway Tag Change scripts.
It seems to me that the new SFC Module would be good to use to handle this kind of batch logic. Check it out here: inductiveautomation.com/whatsnew#sequential
Carl gave a pretty good demonstration of the new SFC module in the Ignition 7.7 webinar. The webinar is here: inductiveautomation.com/vid … 77-release