BidSystem, online auction, problem with timing - asp.net

guys!
I'm developing an online auction with time limit.
The ending time period is only for one opened auction.
After logging into the site I show the time left for the open auction. The time is calculated in this way:
EndDateTime = Date and Time of end of auction;
DateTime.Now() = current Date and Time
timeLeft= (EndDateTime - DateTime.Now()).Seconds().
In javascript, I update the time left by:
timeLeft=timeLeft-1
The problem is that when I login from different browsers at the same time the browsers show a different count down.
Help me, please!

I guess there will always be differences of a few seconds because of the server processing time and the time needed to download the page.
The best way would be to actually send the end time to the browser and calculate the time remaining in javascript. That way the times should be the same (on the same machine of course).

Roman,
I had a little look at eBay (they know a thing or two about this stuff :)) and noticed that once the item is inside the last 90 seconds, a GET request gets fired every 2 seconds to update the variables in the javascript via a json response. you can look at this inside firebug/fiddler to see what it does.
here is an example of the json it pulls down:
{
"ViewItemLiteResponse":{
"Item":[
{
"IsRefreshPage":false,
"ViewerItemRelation":"NONE",
"EndDate":{
"Time":"12:38:48 BST",
"Date":"01 Oct, 2010"
},
"LastModifiedDate":1285932821000,
"CurrentPrice":{
"CleanAmount":"23.00",
"Amount":23,
"MoneyStandard":"£23.00",
"CurrencyCode":"GBP"
},
"IsEnded":false,
"AccessedDate":1285933031000,
"BidCount":4,
"MinimumToBid":{
"CleanAmount":"24.00",
"Amount":24,
"MoneyStandard":"£24.00",
"CurrencyCode":"GBP"
},
"TimeLeft":{
"SecondsLeft":37,
"MinutesLeft":1,
"HoursLeft":0,
"DaysLeft":0
},
"Id":160485015499,
"IsFinalized":false,
"ViewerItemRelationId":0,
"IsAutoRefreshEnabled":true
}
]
}
}
You could do something similar inside your code.
[edit] - on further looking at the eBay code, altho it only runs the intensive GET requests in the last 90 seconds, the same json as above is added when the page is initially loaded as well. Then, at 3 mins or so, the GET request is run every 10 seconds. therefore i assume the same javascript is run against that structure whether it be >90 seconds or not.

This may be a problem with javascript loading at different speeds,
or the setInterval will trigger at slightly different times depending on the loop
i would look into those two

Related

How I can filter meetings which are going to start in given time range

I am working on a specific requirement to filter out any meetings that are going to start in next 15 mins of a given calendar.
I can see that there is timeMax query option which will give events starting before given time but the problem I am facing is that I am also getting older events (which are done in past). Any way to get records only froj now to next 15 mins?
I tried query using syncToken but I guess that doesnt works with timeMax so not able to get just the delta and instead getting all the events.
Calendar Event List API
As suggested under the comments, you could be using timeMin and timeMax. It should be something similar to:
timeMin = 2022-12-27T15:30:00+01:00
timeMax = 2022-12-27T15:45:00+01:00
Notes:
Use the query parameters from above and make sure to respect that it must be RFC3339 timestamp.
This might be the only available option or suggestion when utilizing the event.list to filter them by the 15 minutes mark and check their status. It would be a loop process that could potentially hit a quota.
var request = Calendar.events.list({
'calendarId': calendar_id,
"singleEvents" : true,
"orderBy" : "startTime",
"timeMin": startDate.toISOString(),
"timeMax": maxDate.toISOString()
});
Calendar API limitation
If these suggestions or options are not enough or can be considered workarounds due to the limitations, you could always request a feature by going under Issue Tracker.
References
Events: list
Issue Tracker

How to create an alert to notify an user when some amount % of threshold reached DailyAsyncApex Executions

On 2 occasions in the past month, we have managed to hit our daily limit on asynchronous apex executions. Salesforce temporarily increased our limit to 425000 but it will be scaled down to 250000 in a week's time. Once we reach the limit, a lot of the SF functions will fail and this has tremendously impacted both internal staff and external customers.
So to prevent this from happening in the future, we need to create some kind of alert in Salesforce to monitor our daily asynchronous apex method executions. Our maximum daily limit is 250000. The alert will need to create a P3 helpdesk ticket and notify couple of users say USER A and USER B once it reaches 70% threshold.
Kindly advise what is possible to achieve the same
Thanks & Regards,
Harjeet
There's a promising Limits method but it doesn't seem to work currently ("reserved for future use"): System.debug(Limits.getAsyncCalls() + ' / ' + Limits.getLimitAsyncCalls());
There's an idea you can upvote: https://success.salesforce.com/ideaView?id=0873A0000003VIFQA2 ;)
You could query SELECT COUNT() FROM AsyncApexJob WHERE ... but that sounds like a bad idea ;)
I think your best course of action is to use SF REST API. There's a "limits" resource you can fetch. You could do it from SF itself (bad idea because if you'd schedule it to run every hour then well, of course it will contribute to the limit consumption too ;)) or from some external app that'd connect to your SF...
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_limits.htm
You can quickly try it out for example in workbench.developerforce.com before you decide you do want to deep dive into coding it.
Of course if you have control over your batch jobs, queuable, schedulable & #future calls you could implement some rough counter of executions in a helper object for example... won't help you much if most of the jobs are coming from managed packages though...
Got 1 more idea but it's pretty hardcore - you should be able to make a REST API call from javascript. so you could create a simple VF page (even without any apex controller), put JS callout on it, have it check every 5 mins and do something if threshold is hit... But that means IT person would have to have this page open all the time (perhaps as a home page component)... Messy :)
I was having the exact same issue so I created a simple JsForce script in NodeJS to monitor the call to the /limits endpoint.
You can connect a Free Monitoring service like UpTimerobot.com or PingDom.com and get an email when you find the Word "Warning" >50% or "Error" > 80%.
async function getSfLimits() {
try {
//Let's login into salesforce
const login = await conn.login(SF_USERNAME, SF_PASSWORD+SF_SECURITY_TOKEN);
//Call the API
const sfLimits = await conn.requestGet('/services/data/v51.0/limits');
return sfLimits;
} catch(err) {
console.log(err);
}
}
https://github.com/carlosdevia/salesforcelimits

ASP.Net page not updating - Literally the same screen from earlier (as if back was selected)

I have an ASP.Net application that accesses user data from a SQL database.
Visual Studio Version 2012
Windows Server 2012 Standard 6.2
Sql Server 2012
Program in Service since 11/2007 (with problem having never happened previously)
Problem:
First reported by 2 of my customers but I was not experiencing the problem until after a recent MS update.
Unsure of the particulars of those updates or whether it was only a coincident.
Log into application and go around to a few pages, all seems ok, than I select a new Active Company (auto filters list screens by Active Company ID from a session variable, changing active company changes the ID stored in the session variable), everything works fine for a while (1 - 4 mins) switching between screens and even different active companies, than at one point I go to a page that I've been to several times (that worked fine) and it shows everything from the last time I accessed it (literally the identical page from a few mins ago). I change to another page and it appears to be updated, go back to the screen that did not update and it no matter what, will not update again. I query the database and it is indicating the correct active company ID and query the session variable and that too is correct.
** The strange thing is I can wait 4 -5 mins (I just stop doing anything) and than try to access the page again and now it updates.
I have been beating at this now for almost 2 weeks and have not been able to determine to source of the problem.
I literally have tried every settings for session caching I could read up on with no (or minimal) affect.
Since our software utilizes session variables to hold user variables to control their environment (like active company selection), I went to go as far as removing the session variables and making the profile.variables (requiring Sql Session management) with minimal affect).
It seems to work fine for a few minutes (or page accesses) than once it stops updating the page, it will no longer update under any circumstance.
It will occur on pretty much any combination of page changes (after changing the active company, since it will actually change data displayed).
This design has been out in the field for over 8 years now (and is routinely brought up-to-date with the latest dot.net compiler updates, .net framework and IronSpeed Designer engine updates. This error has never occurred before now. No update to the development tools took place prior to the appearance of this issue.
I tried various tests.
Test 1:
I added java code to reset each page.
<script type="text/javascript">
function RefreshPage()
{
window.location.reload()
}
</script>
Result: No change
Test 2:
I stopped as soon as the page did not refresh and started timing when the page would update (1 -2 mins or going back and forth between the change active company and the reports screen several times)
Result:
After 60 - 90 secs, the current page seemed to do an update (the activity icon would appear than go away) so I would than check the page the was not refreshing and it was now correct.
Since I was using the report page for my tests, I would run a report when the screen update failed, to see what active company it thought it was on (since it was also reliant on the session variable, it was bringing up the correct report data, even though the page was not indicating the correct active company. Note: Every one of our screens indicate the current user and active company name at the top, so it is easy to see when it is not updating.
Any direction as to where to look from here would be greatly appreciated, I'm at a lost as to what to check now.
P.S. I installed MS Message Analyzer and had it monitor up to the point where I get a failure. I have never user MS MA before so I don't have much of an idea as to what to look for, other than the operation status was indicating Found (302) for the Get and Post and Ok (200) for the page I received the problem for.
Thanks in advanced!
John R
I propose to check caching options. I mean caching of page, controls, javascript, and browser. As workaround I propose to add some empty paramether to your page, ajax calls. For example instead opening "default.aspx" open "default.aspx?id=someNewGoid". Also consider adding some random paramethers to your ajax calls.
Try following coe for refresh:
<script type="text/javascript">
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid()
{
var guid = (S4() + S4() + "-" + S4() + "-4" + S4().substr(0,3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
return guid;
}
function RefreshPage()
{
var url = window.location;
if (url.indexOf("?")>-1){
url = url.substr(0,url.indexOf("?"));
}//this par will cut of additional paramthers
window.location = url + "?id=" + guid();
window.location.reload()
}
</script>

Infinite loop calling getSiteRefreshInfo

About 2 weeks ago I wrote a program implementing the Add Site Account flow chart.
I ran it a number of times over a span of several days, and it worked fine each time.
Then I worked on other things, and about a week later tried running the above program again. Now it did not work, but got into a seemingly infinite loop on the call to getSiteRefreshInfo (the loop in the lower left corner of the flow chart.) I tried running this a number of times over the next 3-4 days, and got into a loop each time. It looped for 20-30 minutes before I killed the program. This is exactly the same source code that worked correctly a week earlier, using exactly the same credentials.
Each time "code" was 0, and "siteRefreshStatus" was "LOGIN_SUCCESS", which according to the flowchart meant I should wait 2-4 seconds and then repeat the call:
{
"siteRefreshStatus": {
"siteRefreshStatusId": 2,
"siteRefreshStatus": "LOGIN_SUCCESS"
},
"siteRefreshMode": {
"refreshModeId": 2,
"refreshMode": "NORMAL"
},
"updateInitTime": 1418945894,
"nextUpdate": 1418946794,
"code": 0,
"itemRefreshInfo": [
{
"memItemId": 10070147,
"itemSuggestedFlow": {
"suggestedFlowId": 2,
"suggestedFlow": "REFRESH"
},
"errorCode": 405,
"retryCount": 0
}
],
"noOfRetry": 0
}
The account I'm passing to addSiteAccount1 is an American Express credit card account, and this is the only account I've added for this user (in other words, this is the only account that needs to be refreshed). Once while the program was in a loop, I manually logged onto the American Express website using these same credentials, and I could view the account, get the list of recent transactions, etc. I realize that Yodlee probably uses a different interface than the browser does, but this did show me that the Amex website was up and functional.
I tried letting the loop run for more than 30 minutes to see what happened. After an hour and 55 minutes I got this exception:
{
"errorOccurred": "true",
"exceptionType": "Unknown Exception Occurred",
"referenceCode": "_022c5fa3-3933-4491-b390-1150d8b28ab3",
"detailedMessage": "Technical Difficulty Processing Request"
}
I tried running the program various times over the next 3-4 days and it got into a loop each time. Then it abruptly started running correctly again, and at the moment is still running correctly. Note that the exact same source code and credentials ran correctly for a while, then got into a loop for 3-4 days, and is now running correctly again.
I have two questions about this:
1) How should I exit from such a loop? The way I interpret the API Flowchart is that I should loop until I get a value for "code" or "siteRefreshStatus" that tells me to exit the loop. I could easily implement my own timer, but I don't know what time value would be appropriate in all cases. Yodlee is in a better position to know if the loop has gone on for too long, so I would expect a return like REFRESH_TIMED_OUT in this case.
2) If we had been running this code in production, we would not have been able to refresh this customer's information for at least 3 days, which for our application would be an extremely long time. Is there anything else we can try in this case?
Thanks!!!
I think you're suffering from a different issue: your itemRefreshInfo has error code 405, which this page says is: "Update Request Canceled(405):Your account was not updated because you canceled the request."
I believe you're cancelling your request somehow.

How to get time remaining in Groupon Html?

I cannot get time remaining from groupon HTML. I did find a method before by hitting the link and it returned in JSON format, but that link no longer works.
So is there any way to get the time remaining from the deals? Only for goods, getaways, and all deals.I can get from the now deals(that is just text) unlike others which is a countdown counter.
To be on same page lets start with this link:
http://www.groupon.com/deals/3rd-coast-cruising-1?c=all&p=23
And before I used to hit:
http://www.groupon.com/deals/3rd-coast-cruising-1/deal_status.json
And got information including the remaining time, but it's not doing so any longer.
It's still there, in the form of a timestamp. Using the source of the first link:
<li class='groupon_countdown' data-deadline='1337576399' ...
And in the second link:
"deadline":"1337576399"
I don't know what language you're using, but with python you can convert this to a readable format like this:
>>>import time
>>>time.asctime(time.localtime(1337576399))
'Mon May 21 06:59:59 2012'
Which corresponds with now + the time left on their timer, in my timezone anyway.

Resources