Skip to content

Commit

Permalink
treewide: Make uploads asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Feb 4, 2025
1 parent 17f220f commit 21362eb
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions Packages/MIES/MIES_MiesUtilities_Uploads.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ Function UploadCrashDumpsDaily()
return NaN
endif

if(UploadCrashDumps())
printf "Crash dumps have been successfully uploaded.\r"
endif
UploadCrashDumps()

JSON_SetString(jsonID, "/diagnostics/last upload", GetIso8601TimeStamp())
AbortOnRTE
Expand Down Expand Up @@ -142,7 +140,7 @@ static Function UploadPing()

jsonID = GenerateJSONTemplateForUpload()
AddPayloadEntries(jsonID, {UPLOAD_BLOCK_USERPING}, {payload}, isBinary = 0)
UploadJSONPayload(jsonID)
UploadJSONPayloadAsync(jsonID)

return err
End
Expand Down Expand Up @@ -175,8 +173,6 @@ End
/// The uploaded files are moved out of the way afterwards.
///
/// See `tools/http-upload/upload-json-payload-v1.php` for the JSON format description.
///
/// @return 1 if crash dumps had been uploaded, 0 otherwise
Function UploadCrashDumps()

string diagSymbPath, basePath, diagPath
Expand All @@ -192,12 +188,9 @@ Function UploadCrashDumps()
numLogs = DimSize(logs, ROWS)

if(!numFiles && !numLogs)
return 0
return NaN
endif

printf "Please wait while we upload %d crash dumps. This might take a while.\r", numFiles + numLogs
ControlWindowToFront()

jsonID = GenerateJSONTemplateForUpload()

AddPayloadEntriesFromFiles(jsonID, files, isBinary = 1)
Expand All @@ -213,15 +206,16 @@ Function UploadCrashDumps()
SaveTextFile(JSON_dump(jsonID, indent = 4), diagPath + ":" + UniqueFileOrFolder(basePath, "crash-dumps", suffix = ".json"))
#endif // DEBUGGING_ENABLED

UploadJSONPayload(jsonID)
UploadJSONPayloadAsync(jsonID)

#ifndef DEBUGGING_ENABLED
MoveFolder/P=$basePath "Diagnostics" as UniqueFileOrFolder(basePath, "Diagnostics_old")
#endif // DEBUGGING_ENABLED

DEBUGPRINT_ELAPSED(referenceTime)

return 1
printf "Uploading %d crash dumps is in progress in the background.\r", numFiles + numLogs
ControlWindowToFront()
End

/// @brief Upload the MIES and ZeroMQ logfiles
Expand All @@ -234,7 +228,7 @@ Function UploadLogFiles([variable verbose, variable firstDate, variable lastDate

string logPartStr, fNamePart, file, ticket, timeStamp
string path, location, basePath, out
variable ret, jsonID, numFiles, i, j, doFilter, isBinary, lastIndex, jsonIndex, partCnt, sumSize, fSize
variable jsonID, numFiles, i, j, doFilter, isBinary, lastIndex, jsonIndex, partCnt, sumSize, fSize

isBinary = 1
verbose = ParamIsDefault(verbose) ? 1 : !!verbose
Expand Down Expand Up @@ -334,22 +328,14 @@ Function UploadLogFiles([variable verbose, variable firstDate, variable lastDate
sprintf out, "Uploading %.0f MB (~%d Bytes)", sumSize / MEGABYTE, sumSize
UploadLogFilesPrint(out, verbose)
for(jsonID : jsonIDs)
ret = UploadJSONPayload(jsonID)

if(ret)
sprintf out, "Error uploading the logfiles.\r"
UploadLogFilesPrint(out, verbose)
Make/FREE/N=(DimSize(jsonIDs, ROWS)) junk = JSON_Release(jsonIDs[p], ignoreErr = 1)
return NaN
endif
UploadJSONPayloadAsync(jsonID)

UploadLogFilesPrint(".", verbose)
endfor
UploadLogFilesPrint("\r", verbose)
endif
UploadLogFilesPrint("Done.\r", verbose)

sprintf out, "Successfully uploaded the MIES, ZeroMQ-XOP and ITCXOP2 logfiles. Please mention your ticket \"%s\" if you are contacting support.\r", ticket
sprintf out, "Uploading the MIES, ZeroMQ-XOP and ITCXOP2 logfiles is in progress in the background. Please mention your ticket \"%s\" if you are contacting support.\r", ticket
UploadLogFilesPrint(out, verbose)
End

Expand Down

0 comments on commit 21362eb

Please sign in to comment.