Realtime timer that counts down time for ruby on rails app - ruby-on-rails

Im in the need on some advise for a realtime serverside timer that would countdown from say 100 seconds. Reason for serverside timer is no tampering.
currently use delayed job but problem its not realtime i could mimic a timer by creatind job every second, but dirty solution
need to display time in view by getting timer value with ajax call to method that returns servertime on page. Know how to do this just to give idea. reload timer would still countdown correctly even on reload page.
Anyone could advise to get a realtime counter in rails app serverside? I would want to create one or more independant timers i can get a value from in railsapp.

Why don't you just create the record you need, but add a "don't open before" DateTime field you can check to see if it's okay to show it?
This sort of thing is trivial to do, and you can set a timer on the client to count-down in JavaScript, then reload the page with the final data at the appropriate time. If someone is impatient and reloads early, you can compute the number of seconds remaining before it can be shown using simple math:
time_left_in_seconds = record.show_at.to_i - Time.now.to_i
Then all you have to do is show a JavaScript timer for that number of seconds, then trigger a page refresh.

Related

How do I reward the user daily?

I want to reward the user daily in my app, but when the app closes the timer always stops
I've tried doing this...
Timer.scheduledTimer(withTimeInterval: 86400, repeats: true) { _ in
self.points += 100
}
Can you please tell me how to reward the user daily once?
Of course the timer stops; when you close Facebook, does the news feed keep scrolling? No, the answer is no. Especially as third party developers, we have to complete ALL our tasks prior to the data of the app closing. There are functions to keep working for up to ~5min but after that, any relevant data will close.
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate
So, we need to consider how we can get around this. So, what we need to do is
Everytime the app opens, we check the date
If it is the FIRST time the user opens the app, we save the date LOCALLY (UserDefaults)
If not, we need to check if the date is the same day or a different day.
If it is the same day as the saved date, we do nothing
If it is a different day, we will provide the user our reward and then overwrite the date in our local save UserDefaults
I think you need to call the function in the User Defaults (Store info locally). Here it is useful for calling functions only once like display the onboarding.
or on your DB you could set the timer there eg lambda functions on AWS

How to make left time count backward

Example is about groupon.com. As we know it say time left for certain products and counts every second. So I can do it with javascript but server side should I update it through Ajax all products left time attribute every second or how to update it in server without AJAX
Anybody knows?
1) Something should update my products timeLeft on server?
I can't find that something.
Only thing I can do is update them through ajax.
The easiest and best way to do count-downs is client-side. Trying to store and update that kind of information is a huge waste of time, space, and processing.
Basically, your database should have the ending time on it, and that will get sent to the client. Then the client will update every second using javascript:
var timeLeft = product.endTime - currentTime;
Then you can update timeLeft every second.

WF DelayActivity fires immediately?

I have a Workflow I have created and deployed to a Sharepoint 2007 farm. When it runs against an item two delay activities I have created fire immediately.
I have setup a callback on the InitializeTimeoutDuration event. Through logs and debug output I can see that it is setting the delay to one hour. However, at the next SP timer job cycle (less than 5 minutes) the events proceeding the Delay activity fire off.
I'm lost here. Any help is greatly appreciated.
Update
Through some digging I was able to determine why this was firing off. Once the workflow started a record gets added to the ScheduledWorkItems table in the SP Content database. However, the "DeliveryDate" on the record is set to the current time while the "Created" date is set to one hour previous. However, the delay I'm using is 2 hours, so neither of these times make sense to me at all. Going to try hardcoding it....
Update 2
Even with a hardcoded duration the times are off. I hardcoded a 2 hour delay in and the "DeliveryDate" is now one hour in the future while the "Created" date is one hour in the past. So at least the difference between them is good.
Update
Well, that's embarrassing... found the problem. I'm posting it in here for others that may make mistakes like I do. First off, I was not correct in my UTC->local conversion. The times on the database were correct. What was not correct was how I was setting the TimeoutDuration:
// WRONG!
delayActivity.TimeoutDuration = new TimeSpan("1:00:00"); // one hour
what I should have been doing:
// RIGHT!
((DelayActivity)sender).TimeoutDuration = new TimeSpan("1:00:00"); // one hour
once I made that change everything else seems to be fine.
Well, that's embarassing... found the problem. I'm posting it in here for others that may make mistakes like I do. First off, I was not correct in my UTC->local conversion. The times on the database were correct. What was not correct was how I was setting the TimeoutDuration:
// WRONG!
delayActivity.TimeoutDuration = new TimeSpan("1:00:00"); // one hour
what I should have been doing:
// RIGHT!
((DelayActivity)sender).TimeoutDuration = new TimeSpan("1:00:00"); // one hour
once I made that change everything else seems to be fine.

The timeout period elapsed prior to completion of the operation or the server is not responding

I Created A VIEW IN MY ASP.NET MVC APPLICATION.
View class retrieves a data of 6100 rows
that class is used in one of my view which fills grid with data it can also be sorted.
it will load nicely for first time then sorting also works fine but when i click on last page link it takes time and finally gives following error
The timeout period elapsed prior to completion of the operation or the server is not responding
anyone can help me please i am not getting WATS the problem
Sounds like the request time is reaching the max allowed (default in ASP.NET = 30 secs). I don't think its as the back button as much as the request is randomly taking 29 secs, 31 secs, etc.
You may want to try a pagination approach to displaying your data instead of loading 6,100 rows at once - this will reduce the load times.
Check out this link for a pagination example.
Another idea would to use page caching. But I would recommend pagination.

RxSwift: Receive events immediately, unless the last event was processed within a certain interval

New to RxSwift / Reactivex. Basically what I'm trying to do is to make a server call whenever something happens, but make sure it's not done more often than every 10 seconds. Less often if possible.
For instance, whenever an event ("needs update") is generated I'd like to call the server immediately if more than 10 seconds have passed since my last call. If less time has passed I'd like to make the call on the 10 second mark from the last one. It doesn't matter how many events have been generated within these 10 seconds.
I looked at the description of throttle but it appears to starve if events happen very quickly, which isn't desirable.
How can I achieve this?
There's a proposed new operator for RxSwiftExt that would give you something you're looking for, I think. However, it doesn't exist yet. You might want to keep an eye on it, though.
https://github.com/RxSwiftCommunity/RxSwiftExt/issues/10

Resources