refactor repeater workflow

the main goal of this is to make it more testable / callable from
other contexts. just pulling stuff out into another function and
refactoring where needed/appropriate
Merge pull request #1637 from dimagi/repeaters

refactor repeater workflow