Condition To Run Widget

In my layout/main.php I have my own widget which is working. But I want to put certain condition when the widget should run and rest of time it shouldn’t run. For example I have cron process which executes a php script after every 5 minutes and if certain conditions are satisfied it returns true and then the widget should run(it continues till user closes it). But if it returns false then widget shouldn’t run. How can I achieve this? Any hint, suggestion?

You should keep a flag in db to identify if the cron file is running or not and check accordingly in widget.

In widget run method put condition according to flag.