added a periodic worker

The periodic worker will call a function periodically based on an input duration
This is used in simpleworker and periodic worker so I moved the definition