Copied in glowstone scheduler code to be merged to integrate with Flow

So kitskub can merge it