views:

28

answers:

1

Greetings all-

I'm writing a program that parses and cleans a lot of data from one database to another on Matlab, querying from MySQL. This would run continuously, as new data come into the first db every minute, are cleaned, and put to the clean db before the next data point comes in. I was wondering how, during this process, I could account for two things...

  1. Every three nights MySQL is shutdown for backup. I'd like my program to pause when this happens, and resume when its back up. I've looked around for a solution, and can't seem to find one for this.

  2. Allow a user to kill the program. I've narrowed this down to either accounting for a ctrl+c kill, or creating a GUI to do it. Which do you all think would be the better strategy?

Thanks in advance for your time and help on this matter.

A: 

Use a TIMER together with a GUI.

First, create a GUI with two toggle buttons - 'pause' and 'cancel'. When your program starts, launch the GUI and capture its handle. Pass this handle to the timer object. Whenever the timer object is set to execute, it should set the 'Value' property of the 'pause'-button to 1, and at the end of the scheduled maintenance set it back to 0. Meanwhile, your program which runs, I assume, a while loop, should check at every iteration for the value of the pause button. If the button is pressed (i.e. its value is 1), the program should not try and access the database. If the button is released, the program should run as normal.

When the program checks for a pressed pause button, it should also check for a pressed 'cancel' button. If that button is pressed, the function should break the loop and gracefully exit.

In the GUI, you can also set a closeRequestFcn, where you have a dialog pop open to ask whether the user really wants to quit the running database program. If the user chooses 'yes', hide the GUI (set(guiHandle,'Visible',false)) and "press" the cancel button, so that the program can exit. The closeRequestFcn will also execute when you close Matlab without having stopped the program first. This can help you avoid accidentially closing Matlab and thus accidentially killing your process.

Jonas
@Jonas-Thanks for the help, I'll try this and report on it later!
Joey
OK, I'm stuck at setting my GUI's value property of the Pause button. The GUI is named GLEONQAGUI. I run the code below to capture its handle.>> handles = guihandles(GLEONQAGUI)...Now how do I modify these handles to set the Pause button to max or min? I've tried set(handles.togglebutton1,'Value','Max') to no avail. Thanks for the continued support.
Joey
`set(handles.togglebutton1,'Value',1)`. Also, if you find my answer useful, please consider accepting it.
Jonas