Why is TileUpdater.StartPeriodicUpdate not behaving as expected? - windows-store-apps

I've got a windows store app, and I'm setting it up to periodically update the tile. Originally, I set it to use StartPeriodicUpdate(Uri, PeriodicUpdateRecurrence) but it didn't seem to be updating, and because the minimum recurrence is HalfHour, I wanted to use StartPeriodicUpdate(Uri, DateTime, PeriodicUpdateRecurrence), and set the startTime to DateTimeOffset.Now.AddMinutes(5) so that it would wait 5 minutes before updating, to make testing easier. Code:
public void UpdateLiveTile()
{
LiveTileUpdater.Clear();
var uri = TILE_UPDATE_URI; // example
var start = DateTimeOffset.Now.AddMinutes(5);
LiveTileUpdater.StartPeriodicUpdate(uri, start, PeriodicUpdateRecurrence.HalfHour);
}
However, when I run this, the tile updates immediately, instead of updating 5 minutes from when it's called. I would think that calling the override without the startDate parameter would run immediately (it does) and then the other would run after 5 minutes. Does anyone know why it updates right away, or how I can make sure it's delayed?
Edit: Additionally, if anyone knows why the periodic update isn't occurring either, that would be a great help. The server is definitely responding correctly, because the first update works great, but it never changes. Documentation indicates that the start time and periodic interval could both be delayed by up to 15 minutes, but it's way beyond that margin of error, and I'm not getting any updates.

I found the answer on this page (bold is my emphasis):
When you call one of those methods, the URI specified in the call is immediately polled and the tile or badge is updated with the received contents. After this initial poll, Windows continues to provide updates at the requested interval. Polling continues until you explicitly stop it...
I think the reason that the 5 minute refresh wasn't working, then, is that it polls immediately, and then won't poll again sooner than the interval (30 Minutes), but that it would refresh 30 minutes from then instead of now. This last part is speculation, but the above paragraph indicates why it was updating immediately.
For the second part, it looks like it was updating (when I ran on localhost with a breakpoint, the breakpoint was eventually hit and it refreshed the tile), I guess I just didn't wait long enough.

Related

Why are my PushSubscriptions expiring so quickly?

I followed this tutorial to implement push notifications in my web app, and while they work, they stop working very quickly. It seems to handle the first couple of notifications well, but after that, sometimes when less than five minutes has gone by, the subscription expires, according to my back-end. I get an error code of 410 from the push service which the tutorial says is meant to indicate that the subscription expired.
This is crazy, how can a subscription expire in less than five minutes? I searched up my issue and it seems no one else has had this problem, some even saying that subscriptions can last years!
I tried implementing an event listener in my service worker for the "pushsubscriptionchange" event, but according to Serginho's answer, Chrome did not implement that event as of 2019, and I don't think that's changed since then.
Oh, and while Chrome can handle the subscription (but only once/twice as explained above), Firefox doesn't even do anything. I feel like I'm going crazy. If I test the push subscription feature itself using this site, however, it works in Firefox! and Chrome! What are they doing that I'm not? They show the exact same code as the tutorial I linked above.
What even can I do at this point? I've considered perhaps creating an interval with setInterval() and just resubscribing the user every second or so, but I don't think that'll work.
Any help would be appreciated.
You absolutely need to handle the pushsubscriptionchange in your service worker. Otherwise when a subscription expires and is replaced with a new one you will lose it.
Chrome and most browsers actually trigger that event (I don't know where you read something different). I am sure that it is triggered because on our push service we receive thousands of hits per hour from that event.
Take a look at our service worker if you need inspiration on how to implement that event. Then on your server you simply replace the old subscription with the new one.

Difference between timeout and browserTimeout

I just started using Selenium Grid.
The current problem I'm facing is when a test crashes. The browser stays open forever until I arrive and close it myself so the next set of tests can start.
I noticed that the NODE configuration has two timeout configurations, one for -timeout and another for -browserTimeout
For the -timeout, it says the browser will be "released" for another test. For -browserTimeout, it simply doesn't say anything.
I don't understand what it meant by "released".
What I need is the browser to be closed when the timeout happens.
What option will close the browser?
This documentation should help you out
Quoting the documentation
timeout 30 (300 is default) The timeout in seconds before the hub automatically releases a node that hasn't received any requests for more than the specified number of seconds. After this time, the node will be released for another test in the queue. This helps to clear client crashes without manual intervention. To remove the timeout completely, specify -timeout 0 and the hub will never release the node.
browserTimeout On the hub you can also set -browserTimeout 60 to make the maximum time a node is willing to hang inside the browser 60 seconds.
Here's my limited understanding
timeout - This value represents how long should the Grid wait before it treats a particular test session (a particular running test case) as stale, so that that particular test session can be cleaned up and the slot released so that some other test case can basically execute on the node. This parameter is relevant when lets say you are running a test case from within eclipse and you click on the RED button and end your test case abruptly. At that time the client (your test case) hasn't sent a "end-session" signal to the remote. So this session is stale and the grid has to clean up this orphan session.
browserTimeout - This value represents how long should the Grid wait before it treats a particular test session (a particular running test case) as stale, due to the browser getting hung (maybe due to a browser crash or due to a rogue javascript on the web application which has frozen the browser). Here the important thing to note is that the client (the test case running from within your IDE or a Continuous Integration tool such as Jenkins for e.g.,) is still active but its the browser that has got un-responsive.
So to safe guard your executions from orphaned test sessions due to client crashes use timeout and use browserTimeout to safe guard your grid from frozen browsers which refuses to return back and causes stalled test executions.

Updating HTML interface from Server Script

I have written a standard google web app script with server code and a html interface. The web interface prompts the user for a month and year then creates a google document (by copying a template document) for every day in the month selected.
I have got the code working but I would like to provide some sort of status as the code is running. It takes about 4 mins. I put out a message before calling the server code and a message when it completes but I would like to provide progress updates. i.e. "Docs Created 1", "Docs created 2" etc.
I guess what I am really asking is can google server code update something on the web page while it is running?
Thanks.
Will
No, it cannot (AFAIK).
But since it is taking 4 minutes (which is dangerously close to the 6 minute limit), I suggest you create only one document on your function, then return to the client-side. The client-side will then update the status on the screen and call your server-side function again, which will do the second document, return and so on, until you finish.
By doing this you not only updates your client-side but also avoid getting close to the maximum execution limit. The downside, of course, is that you'll add up some seconds to your total execution time. But for long tasks I don't much problem, actually informing the user of your script progress will make it feel faster in comparison.

How stop Chrome from throttling update checks?

I'm developing a packaged app and everytime I make a change that I want to test, I repackage the app and update it. This occurs fairly often but sporadically (between 10 seconds and 10 minutes depending on changes). But every now and again, Chrome suddenly decides I'm asking too often and throttles the app's update requests. After that, it will not update at all (I assume it's in a "timeout" but I have no idea how for how long).
How do I change the throttling threshold? How do I stop Chrome from throttling once it's done so?
Adding the flags at command line did not help: http://www.chromium.org/throttling
//This does not fix the problem
google-chrome --disable-extensions-http-throttling --disable-enforced-throttling
Throttling only occurs if a second update check is done within 5 seconds and the previous check did not find an update. The solution is to wait longer than 5 seconds between unsuccessful checks. (Thanks to RobW for this answer)
The 5 second rule, while undocumented (and unchangeable from a setting) is confirmed in the source code for Chrome(ium):
https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/extensions/updater/extension_updater.cc&l=51
// Require at least 5 seconds between consecutive non-succesful extension update
// checks.
const int kMinUpdateThrottleTime = 5;

catching Exceeded maximum execution time?

Is there anyway of catching this GAS error: "Exceeded maximum execution time"
I mean catching with try ... catch(e) // so far it's not working for me.
Thanks
As written in the comments to your question, thats not possible. But, however, you can set a flag in scriptDB or properties when execution starts and clear that flag when execution comes to a normal end, so you can find out during the next run wether your script came to a regular end when it was run last time and try to take corrective actions if not.
The answer above is correct; it's not possible. An easy alternative to the workaround that pbhd mentioned would be to simply track the runtime of your script (e.g. comparing results of new Date().getTime() at regular intervals) and run whatever you'd include under your catch statement right before you hit the maximum execution time. The maximum is 6 minutes (reference).
That way, you don't have to catch the error -- you can preempt it.
During normal testing, it is possible to accidentally create an infinite (or very long running) loop that consumes the daily execution time limit 100%.
Even if you realize what you have dome wrong immediately, you cannot immediately re-try with Google scripts for another 24 hours - thus slowing down ongoing development significantly and maybe forcing the developer to do some other work , taking his focus/"attention stream" away from the current problem. This is almost always bad.
My product ("IBM OLIVER CICS test/debug" - see Wikipedia article) solved this problem - and many others - around 37 years ago - by having a time limit on any particular transaction and intercepting the resulting time out, allowing options of:-
continuation or
examine/modify variables
"manual" re-try (for the same time) or
abort.
Google could implement this approach just as easily - by "pausing" if execution time is looking too heavy. I had a similar solution to other resources in OLIVER - such as excessive API calls ("possible macro loop") and excessive memory usage.
It seems it takes an "old timer" like me to provide solutions to problems that have existed "since the beginning of time" (and certainly before PC's were thought of).
Googles current "solution" (i.e. absolute limits) only helps Google keep its own servers from being swamped. It would be easy for them to do what OLIVER did all those years ago. By the way there should be no "IBM" prefix on the Wikipedia article - it was my own product and some clown Wikipedia editor altered it to include the prefix.
(By the way, Google do not prevent other scripts on same s/s running - that maybe only use minimal amounts of extra time ( i.e. Scripts on the same spreadsheet still work) . I tried renaming the original script as an experiment but it was stopped after a very short time with "exceeded execution time" error.
GIZ-A-JOB Google - you know its worth it!