I wish to call a function in Polymer element every 60 seconds to autosave to persist a result in database (let's assume that DB operations will happen within 60 secs). How can this be achieved in Polymer?
is setTimeout() a good option? how to use it call a function every 60 seconds which is part of polymer element?
setTimeout(async () => {...},6000); // how to make this function called every 60 seconds?
I wish to have a polymer 2x function being called every x time interval
You can use setInterval for that.
Related
I have an epic that emits SOME_OTHER_ACTION when 5 minutes have passed after SOME_ACTION (using delay operator).
I want to use jest or sinon useFakeTimers method to be able to do the following: dispatch an action, wait 5 minutes and test if another action was dispatched.
I really don't want to use marble diagrams, or inject TestSchedulers.
I also don't want to wait 5 minutes of real time.
const timeBefore = new Date().getTime() / 1000;
store.dispatch(SOME_ACTION);
// wait 5 minutes
jest.runTimersToTime(5 * 60 * 1000);
expect(store.getActions()).toEqual([ SOME_ACTION, SOME_OTHER_ACTION ]);
expect(store.getActions()[1].time).toEqual(timeBefore + 5 * 60 * 1000);
So what I ended up doing is: replaced RxJS with xstream, and used adapter for redux-observable, modified my epics accordingly.
It turns out that Jest doesn't handle Date correctly when using fakeTimers, so I used lolex for fake timers.
See my gist for full example.
(I didn't find easy way to test or replace internal RxJS delay, so I had to use different reactive library).
clock.setTimeout(() => {
expect(store.getActions()).toEqual([trainIncomingAction, reminderAction]);
done();
}, 60 * 60 * 1001);
clock.runToLast();
I have an API created with Laravel 5.2. I am using throttle for rate limiting. In my route file, I have set the following..
Route::group(['middleware' => ['throttle:60,1'], 'prefix' => 'api/v1'], function() {
//
}
As I understood the Laravel throttling, the above script will set the request limit to 60 per minute. I have an application querying the route which repeat every 10 seconds. So, per minute there are 6 request which is much more satisfying the above throttle.
Problem is, my query works until I execute 60 request regardless of time and after 60 request, it responds me 429 Too Many Requests with header Retry-After: 60. As per my understanding, the X-RateLimit-Remaining should update every 1 minute. But it seems never updated until it goes to 0. After become zero, then waits for 60 seconds then updated.
Am I doing anything wrong here.
Currently I wait for an element to appear like this:
let populated = GREYCondition(name: "Wait for UICollectionView to populate", block: { _ in
var errorOrNil: NSError?
EarlGrey().selectElementWithMatcher(collectionViewMatcher)
.assertWithMatcher(grey_notNil(), error: &errorOrNil)
let success = (errorOrNil == nil)
return success
}).waitWithTimeout(20.0)
GREYAssertTrue(populated, reason: "Failed to populate UICollectionView in 20 seconds")
Which polls constantly for 20 seconds for collection view to populate. Is there a better, non-polling way of achieving this?
EarlGrey recommends using its synchronization for waiting for elements rather than using sleeps or conditional checks like waits wherever possible.
EarlGrey has a variable kGREYConfigKeyInteractionTimeoutDuration value in GREYConfiguration that is set to 30 seconds and states -
* Configuration that holds timeout duration (in seconds) for action and assertions. Actions or
* assertions that are not scheduled within this time will fail due to timeout.
Since you're waiting for 20 seconds for your check, you can instead simply change it to -
EarlGrey().selectElementWithMatcher(collectionViewMatcher)
.assertWithMatcher(grey_notNil(), error: &errorOrNil)
and it'll be populated without a timeout.
I like to connect Earl Grey with basic XCTest and I've come up with this simple solution to problem of waiting for elements:
app.webViews.buttons["logout()"].waitForExistence(timeout: 5)
app.webViews.buttons["logout()"].tap()
I was able to build a windows service using a timer that executes a function every 30 minutes.
I want that this function to be executed every half an hour, for example. 00:00, 00:30, 01:00.
It can do that now but I have to start the service for example at 14:00 so it follows this pattern (each 30 minutes).
I want to automate this so if I start the service 14:08 it will still execute at 14:30 and not 14:38.
Extra information:
This is the function I use for the timer
oTimer = New Timer()
oTimer.Interval = 900000
AddHandler oTimer.Elapsed, AddressOf OnTimer
I recommend using either a windows scheduled task or a timed scheduling library such as Quartz.Net. That said this requirement is simple enough that you can quickly built this yourself.
Timers have a due time. This is the time it takes until the first tick. After that the interval time will be used. Set the due time to the difference between now and the next execution (in your case TimeSpan.FromMinutes(30 - 08)).
You can also use a loop:
CancellationToken ct = ...; //Signal this token when you want to shut down the service
while (true) {
var nextDueTime = CalculateDueTime();
var delay = nextDueTime - DateTime.UtcNow;
try {
await Task.Delay(delay, ct);
}
catch (OperationCancelledException) {
break;
}
DoWork(ct);
}
The loop solution is attractive because it avoid typical timer problems such as concurrent ticks and ticks arriving after the timer was stopped.
I have the following code:
// setting timeout to a FULL MINUTE
WebDriverWait wait = new WebDriverWait(driver, 60);
Actions action = new Actions(driver);
// First, click the usermenu
WebElement userMenu = wait.until(ExpectedConditions.elementToBeClickable(By.id("UserMenu")));
userMenu.click();
WebElement adminPortal = driver.findElement(By.id("AdminPortals"));
action.moveToElement(adminPortal);
action.perform();
// Wait for secondary menu to become available
WebElement portal = wait.until(ExpectedConditions.elementToBeClickable(By.id(portalId)));
portal.click();
Basically, "UserMenu" is a drop-down, and there's a hover-over expansion menu "AdminPortals". The above code simulates (in Selenium, the action of clicking on an item in the expanded menu.
The question I have is in relation to the timeout period. When does it start counting down? I assume it is when I use wait.until(). And I assume it stops counting once True is returned by ExpectedConditions? And, the real question is: If I use the same "wait" twice, as I have here, does the 60 seconds reset as the limit between each use, or does it restart counting where it stopped before?
So, if the first wait took 2 seconds, and the second wait took 3 seconds, will the timeout for the third call to wait.until() be 55 seconds, or reset to 60?
Yes, it starts counting down when you call the until method. When you instantiate a new WebDriverWait object and specify a timeout it sets up a clock, so each time you call the util method on that object it will continue to count down the same timer. It doesn't reset the timer each time it returns. If you want the timer to reset you will need to create new WebDriverWait objects.
This is really unclear in the documentation. I had to look at the code to figure out what was going on. The logic is actually inherited from the FluentWait class. Here's the source code link I looked at:
https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/support/ui/FluentWait.java
So, if the first wait took 2 seconds, and the second wait took 3 seconds, the timeout for the third call to wait.until() will be 55 seconds.