You need two refineries, one of them has to run all the time. Then you have a pull chest, that pulls out of the refineries, place the OR beneath the chest.
Your normal sorting system has to pull out of this chest.
Now, if there are raw materials, the always-on-refinerie will pull and do it's...