Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: "Failed to retrieve real time from API, falling back to local time" #84

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

7D7-Development
Copy link

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"

#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.

Replaced http with https inside of retrieveTimeFromApi function.
Fix: "Failed to retrieve real time from API, falling back to local time"
Copy link

@Bellck Bellck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link

@Bellck Bellck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable fix, as API isn't loading real time, and re-loading local time.

@7D7-Development
Copy link
Author

7D7-Development commented Sep 8, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants