added publish_periodically function and changed test example to use it