Author Topic: Waiting "somehow" for shutdown items to complete?  (Read 11613 times)

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Waiting "somehow" for shutdown items to complete?
« on: May 12, 2012, 10:14:37 PM »
Howdy Stu and WeatherCat fans,  [cat]

Today was my first attempt to use WeatherCat to launch and shutdown all my AppleScripts using the launcher scripts I wrote.  Launching works just fine.  Alas, shutting down runs into a problem.  I have pauses so that all the dependent AppleScripts shut down before the two AppleScripts that are used by others quit.  I do this to avoid this problem of one AppleScripts accidentially launching another which is in the process of being shutdown.

Unfortunately, the one thing I cannot "delay" is WeatherCat itself shutting down.  Sure enough, WeatherCat has completely quit before my AppleScripts have.  During the delay at least one of the AppleScripts sends an AppleScript request that - causes WeatherCat to automatically start up again . . . .  >:( 

So I have a humble request (I hope.)  Could either WeatherCat incorporate a delay so that whatever shutdown application has enough time to "do its thing" before WeatherCat shuts down?

Alternatively, could WeatherCat monitor the process of the shutdown application and not start its own shutdown until the shutdown application has itself quit?

Not sure how to do this but toss out the problem for Stu's clever mind to "chomp on."  [computer]

Cheers, Edouard  [cheers1]

WCDev

  • WeatherCat Developer
  • Administrator
  • Storm
  • *****
  • Posts: 2965
    • CW9739
    • IIBSTO2
    • Trixology
  • Station Details: Main Station: Vantage Pro-2, 24hr fars, solar, extra temp stations, no U.V. WeatherLinkLive.
Re: Waiting "somehow" for shutdown items to complete?
« Reply #1 on: May 13, 2012, 03:01:04 PM »
Hi Edouard,
Yes, let me have a think about it and do some investigation - I've added it to the todo list.

Cheers,
Stu.

Randall75

  • Storm
  • *****
  • Posts: 1332
  • CWOP-CW6734 WeatherUnderground-KOHNEWAR6
    • CW6734
    • KOHNEWAR6
    • Randy's Weather On The Hill
  • Station Details: Davis Vantage Pro 2 Plus.iMac i5 OS High Sierra 10.13.6 8GB Ram, WeatherCat 3,Logitech 9000 Pro Web Cam
Re: Waiting "somehow" for shutdown items to complete?
« Reply #2 on: May 13, 2012, 06:10:04 PM »
Hi Edouard
 For this to work better for me I rearranged on which one shut down first for me
1.WC Status Growler
2.WC Web Data Uploader
3.WC AppleScript Tag Processor
4.WC Storm Monitor
5.WC ET Reporter
6.WC Zambretti Forecaster
7. WC Twitter Uploader
and took out the delay
I'm not telling anyone else to do this but this just worked better for me
 [cheers1]

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Thanks Stu (Re: Waiting)
« Reply #3 on: May 13, 2012, 06:22:00 PM »
Howdy Stu and cat fans,

Yes, let me have a think about it and do some investigation - I've added it to the todo list.

Thanks Stu!

As noted elsewhere, got a workaround in AppleScript so it can indeed be added to your todo list in the usual way.

Might be worth pondering how common this problem would be in the long term.  The AppleScripts will need to be somehow redone and a lot the functionally will probably get out of AppleScript completely - so this particular instance of problem may go away.  However, I was wondering about folks who might have other physical devices tied into their weather monitoring rig.  Mike might need to have have other programs shutdown physical hardware.  Also Dan on MacWeather is "gettin' idiers'" about adding hardware.  So the need may remain.

Cheers, Edouard  [cheers1]

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Configuration and timing (Re: Waiting)
« Reply #4 on: May 13, 2012, 06:56:30 PM »
Hi Randall, Stu, and WeatherCat fans,

For this to work better for me I rearranged on which one shut down first for me
. . . . . .


Well, that depends on if you have WC Web Data Uploader and WC Twitter Uploader sending requests to WC Status Growler to see if the Internet is up or not.  If you do, then there is always a chance either one will restart WC Status Growler before you have shut them down.  The same point applies to WC AppleScript Tags Processor.

Now it is true, the longer the delays in the shutdown process, the longer the interval when an AppleScript might make requests to one another or WeatherCat.  Now that you mention this, I think I should knock these values way down.  Even 1/2 a second is plenty of time and the AppleScript delay command accepts decimals.

Even so, it is still "more better" to have Stop WeatherCat Scripts also shutdown WeatherCat instead of using the WeatherCat shutdown action when using my AppleScripts.  Even if the odds can be made very small, there is always a risk that something will be restarted if you don't shut things down in the right order.  If you really want to have a bullet-proof sequence, you have to eliminate any such chance.  It doesn't matter too much I suppose if you restart things "by hand," but if you want to completely automate a restart process say while your sleeping - you don't want a surprise waiting for you when you check your computer in the morning!!  :o

Cheers, Edouard  [cheers1]

P.S. On second thought, the situation is even more complicated.  Even if the shutdown sequence will work perfectly well, there is a possibility of the processing taking a very long time.  The two scripts that upload data to the Internet won't quit in the middle up uploading.  AppleScript isn't smart enough to interrupt the idle handler an AppleScript is "told" to quit.  If there is a request to an upload service and the server is very slow to respond - both WC Web Data Uploader and WC Twitter Uploader could take as long as a minute to quit.  Fortunately, AppleScript doesn't do the next step in the script until the previous one is completed.  So Stop WeatherCat Scripts will patiently wait for each script in turn to quit before telling the next one to do to so.  Nonetheless, it is possible for this process to take as much as several minutes when your Internet connectivity is poor.

P.P.S. On third thought (why am I thinking so much! ) I should remove all the delays in Stop WeatherCat Scripts.  The way AppleScript processes each line guarantees that nothing will be left incomplete as the shutdown sequence unfolds.  The delays are only need for Start WeatherCat Scripts to avoid having WC AppleScript Tags Processor getting requests for all the other AppleScripts at once.

Randall75

  • Storm
  • *****
  • Posts: 1332
  • CWOP-CW6734 WeatherUnderground-KOHNEWAR6
    • CW6734
    • KOHNEWAR6
    • Randy's Weather On The Hill
  • Station Details: Davis Vantage Pro 2 Plus.iMac i5 OS High Sierra 10.13.6 8GB Ram, WeatherCat 3,Logitech 9000 Pro Web Cam
Re: Waiting "somehow" for shutdown items to complete?
« Reply #5 on: May 13, 2012, 07:49:11 PM »
Hi Edouard
 I see what you mean but I don't use the twitter uploader not a tweeter I was just playing around with it after I ask about the scripts restarting WeatherCat when trying to shut it down and so far it has worked for me I know now that I said this it won't work the next time but that's part of exploring
thanks for all your hard work you and Stu will get it worked out I know
 [cheers1]

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
having cake and eating it too (Re: shutdown items to complete?)
« Reply #6 on: May 14, 2012, 12:45:16 AM »
Hi Randall and WeatherCat fans,

I've been scratching my head as I've been scrambling about with the outdoor chores . . . .

I see what you mean but I don't use the twitter uploader not a tweeter I was just playing around with it after I ask about the scripts restarting WeatherCat when trying to shut it down and so far it has worked for me I know now that I said this it won't work the next time but that's part of exploring
thanks for all your hard work you and Stu will get it worked out I know

Actually, what you've done has a very high probably of working perfectly.  Without any delays, there is very little time for a request to "sneak out" and restart anything.  I'll modify my version of the script to remove the delays and update the documentation.  As long as you aren't using some script to automatically restart WeatherCat, it is silly not to have the convenience of using Stu's handy shutdown action.  You may never have a problem, and if you do, it would be months before it would happen again.

However, if you are trying to automate WeatherCat being restarted, my thinking is: "why not use the script instead?"  If you are using Automator, CronniX, so something else, you have already got another program involved.  It isn't any harder to launch Stop WeatherCat Scripts to do the shutdown action and then launch WeatherCat and use the startup actions to put all the AppleScripts back to work.  Also, the idea of having my weather station software broken in some weird state half the night because of a bad restart  . . . . that's not a risk I would be willing to take!!  :(

So that's my latest thinking on this after watering the shrubs, blowing all the debris, and preparing for the arborists who are coming tomorrow to trim our Sequoia trees. . . . . . Don't know if that is best way to solve this sort of problem, but it will have to do!

Cheers, Edouard  [cheers1]

Randall75

  • Storm
  • *****
  • Posts: 1332
  • CWOP-CW6734 WeatherUnderground-KOHNEWAR6
    • CW6734
    • KOHNEWAR6
    • Randy's Weather On The Hill
  • Station Details: Davis Vantage Pro 2 Plus.iMac i5 OS High Sierra 10.13.6 8GB Ram, WeatherCat 3,Logitech 9000 Pro Web Cam
Re: Waiting "somehow" for shutdown items to complete?
« Reply #7 on: May 14, 2012, 02:20:01 AM »
Hi Edouard
 No I'm not using any other scripts than your startup and shut scripts
It was that it would restart WC before all scripts were to quit so I just rearranged which ones to quit first and took out the delays and was working the last few times i was testing it using your scripts now I wanting to run WC for a week or two with out restarting it to see how stable it is here.


Will your scripts run OK if I shut down Growl while I'm on vacation so that my screen is not full of stickies when i get back or how to turn off the stickies so that they don't stay on the screen?
thanks
 [cheers1]


elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Use Growl to stop notifications (Re: Waiting)
« Reply #8 on: May 14, 2012, 06:09:27 PM »
Howdy Randall and WeatherCat Voyagers . . . .

No I'm not using any other scripts than your startup and shut scripts
It was that it would restart WC before all scripts were to quit so I just rearranged which ones to quit first and took out the delays and was working the last few times i was testing it using your scripts now I wanting to run WC for a week or two with out restarting it to see how stable it is here.

Okay sounds like to have things under control.  I'll revise my stop script along the lines you suggest as I noted earlier.

Will your scripts run OK if I shut down Growl while I'm on vacation so that my screen is not full of stickies

In a word - NO!!

how to turn off the stickies so that they don't stay on the screen?

Shucks Randall, with my wagon on injured reserve, I haven't thought about such things!!  ;D

So, a quick bit of research.  In your case, the easiest thing to do is to use the "master control switch" and turn off all notifications all together.  You can do that on the General tab of the Growl preference pane.  Here is an image of what that looks like:



You can also do the same thing for individual applications without turning off everything.  Here is a screenshot for Growl 1.2 that shows what to do:



For each AppleScript application, uncheck the box in the Growl preference pane.  The scripts will then run as they always do.  Growl will simply not create a notification when the AppleScript asks. 


Whether you stop the notifications at the "master switch" or on an application by application basis, When you get back from vacation, check the box (or boxes) and the AppleScript will resume giving you notifications with Growl.

Hope that's clear and straightforward enough!!

Cheers, Edouard  [cheers1]

Randall75

  • Storm
  • *****
  • Posts: 1332
  • CWOP-CW6734 WeatherUnderground-KOHNEWAR6
    • CW6734
    • KOHNEWAR6
    • Randy's Weather On The Hill
  • Station Details: Davis Vantage Pro 2 Plus.iMac i5 OS High Sierra 10.13.6 8GB Ram, WeatherCat 3,Logitech 9000 Pro Web Cam
Re: Waiting "somehow" for shutdown items to complete?
« Reply #9 on: May 14, 2012, 10:39:33 PM »
Hi Edouard
 That's what I thought but wanted to hear it from the expert
If don't ask you won't know for sure
thanks
 [cheers1]

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
to be honest - never tried it before!! (Re: Waiting)
« Reply #10 on: May 14, 2012, 11:52:44 PM »
Hi Randall and WeatherCat fans,  [cat]

That's what I thought but wanted to hear it from the expert
If don't ask you won't know for sure

To be honest, I had noticed those things before but never bothered to figure out how they worked - never had a need for it!  :o

Does that mean I'm overdue for a vacation?  8)

Cheers, Edouard  [cheers1]

Randall75

  • Storm
  • *****
  • Posts: 1332
  • CWOP-CW6734 WeatherUnderground-KOHNEWAR6
    • CW6734
    • KOHNEWAR6
    • Randy's Weather On The Hill
  • Station Details: Davis Vantage Pro 2 Plus.iMac i5 OS High Sierra 10.13.6 8GB Ram, WeatherCat 3,Logitech 9000 Pro Web Cam
Re: Waiting "somehow" for shutdown items to complete?
« Reply #11 on: May 15, 2012, 01:05:36 AM »
Edouard
 As soon as the big block is in and purring its time [biggrin]


 [cheers1]


Mine will be a working vacation to fix what ever mom needs done 928 miles and 15 hrs and 40 minutes of straight driving if no problems


 [cheers1]

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
All you'll need after that is - a vacation!! (Re: Waiting)
« Reply #12 on: May 15, 2012, 06:42:58 PM »
Howdy Randall and WeatherCat voyagers . . . .

Mine will be a working vacation to fix what ever mom needs done 928 miles and 15 hrs and 40 minutes of straight driving if no problems

 ;) Huh??? . . . that's what you call a vacation?

Ya' know, I don't think you've got the concept down right exactly . . . . maybe you should check out the Wikipedia entry on this one!!

Otherwise, as soon as you finish your "vacation" . . . . ya' know what you'll be needing? . . . . . . a real vacation!!  [lol2]


Cheers, Edouard  [cheers1]

P.S. Sure is getting frightening what you can find on Wikipedia!!  :o

WCDev

  • WeatherCat Developer
  • Administrator
  • Storm
  • *****
  • Posts: 2965
    • CW9739
    • IIBSTO2
    • Trixology
  • Station Details: Main Station: Vantage Pro-2, 24hr fars, solar, extra temp stations, no U.V. WeatherLinkLive.
Re: Waiting "somehow" for shutdown items to complete?
« Reply #13 on: May 15, 2012, 06:46:39 PM »
Hi Edouard,
Nothing obvious has sprung up - the issue is that WeatherCat can launch anything on shutdown - it may not be something it can monitor. I think we'll have to come up with some mechanism to manage it that might involve some coordination between WeatherCat and script to coordinate things.

I'm just off camping for a few days, but when I get back will have a play to see what I can come up with (I'll probably drop you an email when I have something).

Cheers,
Stu.

Good luck with the trip Randall! We're towing 200 miles tomorrow, not sure I could manage 928 miles  :)

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6665
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Happy towing!! (Re: Waiting "somehow")
« Reply #14 on: May 15, 2012, 07:42:07 PM »
Howdy Stu and feline adventurers!  [cat]

Nothing obvious has sprung up - the issue is that WeatherCat can launch anything on shutdown - it may not be something it can monitor. I think we'll have to come up with some mechanism to manage it that might involve some coordination between WeatherCat and script to coordinate things.

Well, I had a simple-minded UNIX-styled mechanism in my head.  We can toss that idea around when you get back.

I'm just off camping for a few days. . . . . We're towing 200 miles tomorrow. . . .

Enjoy the expedition!!! You are making me ever more anxious to get my trusty wagon back into service!!

Cheers, Edouard  [cheers1]