The new PoW solver does this for you already. Check question Questions about mining script for an interesting discussion.
The best you can do in this 1.7 update is to make sure your node has many peers at all times so that your node is in sync with the tip at all times. I recommend making sure there’s always at least one peered connection to a Gluwa’s Node, and use the endpoint /peers to make sure your network is healthy, if it gets unresponsive, restart your node immediately, also activate the verbose flags -vv and look continuously for ‘claimed’ logs, meaning that your node is actively publishing new blocks. If any of the above looks odd, restart your node. it may be also possible that the network difficulty gets too high for your system in which case you wont see blocks being claimed too often but, you should still see logs coming from the consensus and the publisher.