Fix: "Failed to retrieve real time from API, falling back to local time"
Replaced http with https inside of retrieveTimeFromApi function.
Describe Pull request This is to fix the error: "Failed to retrieve real time from API, falling back to local time"
https://github.com/qbcore-framework/qb-weathersync/issues/83
Questions (please complete the following information):
- Have you personally loaded this code into an updated qbcore project and checked all it's functionality? Yes.
- Does your code fit the style guidelines? Yes.
- Does your PR fit the contribution guidelines? Yes.
After more testing, I found that the error would still occur at random, just not after every restart, as in the results before the change above.
I added to the failedCount and Wait because it seems the actual deeper issue stems from the API that is being used, as it sometimes randomly can have a longer than usual delay to load the location and time information, here is where I did further testing to get the error to go away entirely:
-- THREAD LOOPS
CreateThread(function()
local previous = 0
local realTimeFromApi = nil
local failedCount = 0
while true do
Wait(0)
local newBaseTime = os.time(os.date("!*t")) / 2 + 360 --Set the server time depending of OS time
if Config.RealTimeSync then
newBaseTime = os.time(os.date("!*t")) --Set the server time depending of OS time
if realTimeFromApi == nil then
retrieveTimeFromApi(function(unixTime)
realTimeFromApi = unixTime -- Set the server time depending on real-time retrieved from API
end)
end
while realTimeFromApi == nil do
if failedCount > 60 then --DEFAULT 10 -- TESTING HERE
print("Failed to retrieve real time from API, falling back to local time")
break
end
failedCount = failedCount + 1
Wait(1000) --DEFAULT 100 -- TESTING HERE
end
if realTimeFromApi ~= nil then
newBaseTime = realTimeFromApi
end
end
if (newBaseTime % 60) ~= previous then --Check if a new minute is passed
previous = newBaseTime % 60 --Only update time with plain minutes, seconds are handled in the client
if freezeTime then
timeOffset = timeOffset + baseTime - newBaseTime
end
baseTime = newBaseTime
end
end
end)
I have made the changes, but the Error appears after joinging game, not directly when re-starting the server, as it was before fixing.
Did you change http to https and also copy paste the above changes? I haven't seen this message again after making these changes, on multiple servers.
So is this good to go? @7D7-Development
Good to go brother. @GhzGarage
Good to go brother. @GhzGarage
I have still the error "Failed to retrieve real time from API.....etc"
Why cant this problem not be solved?
Good to go brother. @GhzGarage
I have still the error "Failed to retrieve real time from API.....etc"
Why cant this problem not be solved?
You must download the latest release then put in ALL of the above changes manually for this fix to work. @ayvaniniyisi If you click "Files changed" above, you can see where you need to make the changes. This has been tested on multiple servers for well over a month now and this error is entirely gone for these servers.
You must download the latest release then put in ALL of the above changes manually for this fix to work. @ayvaniniyisi If you click "Files changed" above, you can see where you need to make the changes. This has been tested on multiple servers for well over a month now and this error is entirely gone for these servers.
But the point is that then the clock is taken from the API so that all players have the API clock and not the local time is accessed. Is that the case now?
@ayvaniniyisi The intention is to use the API to get the time of the machine that the FiveM server is running on, then sync all clients to that time instead of the usual sped up time when NOT using this option in the config.
After this PR is approved and pushed it will be fixed OR you can do the above changes as mentioned.