Skip to content

Commit

Permalink
add webget save entry 'time_ran'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 15, 2020
1 parent b3dd2ab commit 9c640f7
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public WebGetCommand() {
// <entry[saveName].failed> returns whether the webget failed. A failure occurs when the status is not 2XX/3XX or webget failed to connect.
// <entry[saveName].result> returns the result of the webget. This is null only if webget failed to connect to the url.
// <entry[saveName].status> returns the HTTP status code of the webget. This is null only if webget failed to connect to the url.
// <entry[saveName].time_ran> returns a DurationTag indicating how long the web connection processing took.
// <ElementTag.url_encode>
//
// @Usage
Expand Down Expand Up @@ -204,6 +205,7 @@ public void webGet(final ScriptEntry scriptEntry, final ElementTag data, Element
BufferedReader buffIn = null;
HttpURLConnection uc = null;
try {
long timeStart = System.currentTimeMillis();
URL url = new URL(urlp.asString().replace(" ", "%20"));
uc = (HttpURLConnection) url.openConnection();
uc.setDoInput(true);
Expand Down Expand Up @@ -239,6 +241,7 @@ else if (data != null) {
buffIn.close();
buffIn = null;
}
final long timeDone = System.currentTimeMillis();

DenizenCore.schedule(new Schedulable() {
@Override
Expand All @@ -248,6 +251,7 @@ public boolean tick(float seconds) {
if (saveFile == null) {
scriptEntry.addObject("result", new ElementTag(sb.toString()));
}
scriptEntry.addObject("time_ran", new DurationTag(timeDone / 1000.0));
scriptEntry.setFinished(true);
return false;
}
Expand Down

0 comments on commit 9c640f7

Please sign in to comment.