Normal Topic A Better Way To Stop A Mass Update? (Read 1176 times)
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
A Better Way To Stop A Mass Update?
Apr 16th, 2014 at 1:00pm
Print Post Print Post  
Hi all,

I've built a mass update function that issues SMS texts, which is working wonderfully.  However, sometimes the task runs past 5pm, and we want to kill the job in progress.

Ctrl-Shift-End doesn't seem to work, because it stops that instance of the mass update, goes to the next file, and continues on.  So that leaves us with the handy Ctrl-Alt-Del and kill the version of Sesame.

Is there a better 'off button' we can build into the mass update, so we can use some sort of keystroke to properly end the mass update rather than the harsh killing of a client session?

Thanks,
Blair
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: A Better Way To Stop A Mass Update?
Reply #1 - Apr 16th, 2014 at 4:41pm
Print Post Print Post  
BWETTLAUFER wrote on Apr 16th, 2014 at 1:00pm:
Ctrl-Shift-End doesn't seem to work, because it stops that instance of the mass update, goes to the next file, and continues on. 


Next file? Are you saying that it goes on to the next record?

In any case, you could have the mass update check the time of day, or a flag in a file, and not do anything other than advance records, if it is too late or the flag is set.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: A Better Way To Stop A Mass Update?
Reply #2 - Apr 16th, 2014 at 9:57pm
Print Post Print Post  
Hi Mark,

Yes, it's moves on to the next file to process the mass update.

I think an interrupt flag would be great.  A time limiter is a good fallback, but occasionally a staff member stays late, and wants to kill the job when they leave for the day.  Is there a way to check a keystroke that's buffered, or can you think of a simple toggle that could check an external text file, or some such thing?
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: A Better Way To Stop A Mass Update?
Reply #3 - Apr 17th, 2014 at 1:12pm
Print Post Print Post  
BWETTLAUFER wrote on Apr 16th, 2014 at 9:57pm:
Hi Mark,

Yes, it's moves on to the next file to process the mass update.


Do you mean the next record or do you have multiple files it is processing?

Quote:
I think an interrupt flag would be great.  A time limiter is a good fallback, but occasionally a staff member stays late, and wants to kill the job when they leave for the day.  Is there a way to check a keystroke that's buffered, or can you think of a simple toggle that could check an external text file, or some such thing?


Checking a keystroke is difficult for exactly the same reason it is difficult to interrupt a mass update using CTRL-SHIFT-End.

GUI programs, like Sesame client are either waiting on the "event loop" or are processing based on the last event. A mass update is a lot of processing in response to an event. It can check with the event loop to see if any events need to be dealt with, but doing so opens up the possibility that the user will make menu selections or keystrokes that will distract Sesame, rather than dedicatedly running the mass update. So we set a bunch of flags telling the Sesame window to ignore most events while the MU is running, and only check the event loop for the magic keystroke once per each top level record. A sudden interruption to a MU is usually a bad mistake, in that it may leave a record half modified.

If Sesame gets that keystroke, it should stop advancing the top level record soon afterward and interrupt the MU. But, even if that works, it may be better to let the MU run to completion, but simply skip doing anything more to the subsequent records. This can be done by checking if a file contains a flag, or exists at all, and then bracing the "main" program with a conditional. You could attempt to read the keyboard using @GetFromKeyboard and then forcing the current record to the last record to end the MU, or setting a global flag and doing nothing more to each record and letting Sesame advance to the end of the set.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: A Better Way To Stop A Mass Update?
Reply #4 - Apr 17th, 2014 at 2:21pm
Print Post Print Post  
I tried @getfromkeyboard(), but it waited on each file waiting for some sort of keystroke.

What about building into my mass update the following routine

- delete a text file kept on the local machine at c:\sesame2\data\stop.txt
- run the SMS routine
- check to see if there is a text file called stop.txt
- if there is a text file called stop.txt, jump to the end record

I could then build into one of my screens a 'stop' command button that can create the local text file, which will halt the local client process from a second client session.

Do you see any reason why that might not work?

Thanks,
Blair
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: A Better Way To Stop A Mass Update?
Reply #5 - Apr 17th, 2014 at 2:51pm
Print Post Print Post  
BWETTLAUFER wrote on Apr 17th, 2014 at 2:21pm:
I tried @getfromkeyboard(), but it waited on each file waiting for some sort of keystroke.

What about building into my mass update the following routine

- delete a text file kept on the local machine at c:\sesame2\data\stop.txt
- run the SMS routine
- check to see if there is a text file called stop.txt
- if there is a text file called stop.txt, jump to the end record

I could then build into one of my screens a 'stop' command button that can create the local text file, which will halt the local client process from a second client session.

Do you see any reason why that might not work?

Thanks,
Blair


The only sticking point I see with that plan are jumping to the last record and being able to check if the file exists fast enough.

It may be better to make all of the programming in the MU conditional on the file not existing, rather than trying to force the current record. That way, there is little chance that the MU would reset the current record (I'm not sure if it will).

Can you think of any reason why CTRL-SHIFT-End is not working for you in your case? I just tried it here with a simple MU and it stopped quite happily.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: A Better Way To Stop A Mass Update?
Reply #6 - Apr 17th, 2014 at 3:24pm
Print Post Print Post  
You may be able to glean some info using "@EventState" as opposed to waiting on the keyboard. It doesn't wait and may be enough to tell you the user wants out.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: A Better Way To Stop A Mass Update?
Reply #7 - Apr 21st, 2014 at 4:08pm
Print Post Print Post  
Okay, I think I have my solution ... with one small issue.

When I run my mass update, in GLOBAL code it creates the following text file on the client machine:

Code
Select All
if gProceed = "YES"
{
	vFileHandle = fileOpen("C:\Sesame2\keepgoing.txt")
	FileWrite("C:\Sesame2\keepgoing.txt",@serverdate())
	FileClose("C:\Sesame2\keepgoing.txt")
}
 



And as it runs each item in the mass update, in not-GLOBAL code, it checks for the text file, jumping to the end if the file disappears:

Code
Select All
if not FileExists("C:\Sesame2\keepgoing.txt")
{
	FormResultSetCurrentPosition("DR Screen", @resultsettotal())

}
 



However, my delete function doesn't work because it says the text file is in use by Sesame -- even though I used the FileClose command.  Why is that?
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: A Better Way To Stop A Mass Update?
Reply #8 - Apr 21st, 2014 at 4:48pm
Print Post Print Post  
I'm surprised that that doesn't get a syntax error. You need:
Code
Select All
FileClose(vFileHandle)
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: A Better Way To Stop A Mass Update?
Reply #9 - Apr 21st, 2014 at 4:50pm
Print Post Print Post  
Also, did you try using @EventState? It looks like it may be a simpler solution.

I am still confused why the CTRL-SHIFT-End combo does not work for you.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged