16
16
17
17
package de .upb .cs .swt .delphi .cli .commands
18
18
19
+ import java .util .concurrent .TimeoutException
19
20
import java .util .concurrent .TimeUnit
20
21
21
22
import akka .actor .ActorSystem
@@ -29,7 +30,6 @@ import akka.util.ByteString
29
30
import de .upb .cs .swt .delphi .cli .Config
30
31
import de .upb .cs .swt .delphi .cli .artifacts .SearchResult
31
32
import de .upb .cs .swt .delphi .cli .artifacts .SearchResultJson ._
32
- import de .upb .cs .swt .delphi .cli .commands .RetrieveCommand .information
33
33
import spray .json .DefaultJsonProtocol
34
34
35
35
import scala .concurrent .duration ._
@@ -59,40 +59,48 @@ object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProto
59
59
Http ().singleRequest(HttpRequest (uri = searchUri, method = HttpMethods .POST , entity = entity))
60
60
}
61
61
62
- val response = Await .result(responseFuture, 10 seconds)
63
- val resultFuture : Future [String ] = response match {
64
- case HttpResponse (StatusCodes .OK , headers, entity, _) =>
65
- entity.dataBytes.runFold(ByteString (" " ))(_ ++ _).map { body =>
66
- body.utf8String
62
+ try {
63
+ val response = Await .result(responseFuture, Duration (config.timeout + " seconds" ))
64
+ val resultFuture : Future [String ] = response match {
65
+ case HttpResponse (StatusCodes .OK , headers, entity, _) =>
66
+ entity.dataBytes.runFold(ByteString (" " ))(_ ++ _).map { body =>
67
+ body.utf8String
68
+ }
69
+ case resp@ HttpResponse (code, _, _, _) => {
70
+ error(config)(" Request failed, response code: " + code)
71
+ resp.discardEntityBytes()
72
+ Future (" " )
67
73
}
68
- case resp@ HttpResponse (code, _, _, _) => {
69
- error(config)(" Request failed, response code: " + code)
70
- resp.discardEntityBytes()
71
- Future (" " )
72
74
}
73
- }
74
-
75
- val result = Await .result(resultFuture, Duration .Inf )
76
75
77
- val took = ( System .nanoTime() - start).nanos.toUnit( TimeUnit . SECONDS )
76
+ val result = Await .result(resultFuture, Duration . Inf )
78
77
79
- if (config.raw || result.equals(" " )) {
80
- reportResult(config)(result)
81
- }
78
+ val took = (System .nanoTime() - start).nanos.toUnit(TimeUnit .SECONDS )
82
79
83
- if (! (config.raw || result.equals(" " )) || ! config.csv.equals(" " )) {
84
- val unmarshalledFuture = Unmarshal (result).to[List [SearchResult ]]
80
+ if (config.raw || result.equals(" " )) {
81
+ reportResult(config)(result)
82
+ }
85
83
86
- val processFuture = unmarshalledFuture.transform {
87
- case Success (unmarshalled) => {
88
- processResults(config, unmarshalled, took)
89
- Success (unmarshalled)
90
- }
91
- case Failure (e) => {
92
- error(config)(result)
93
- Failure (e)
84
+ if (! (config.raw || result.equals(" " )) || ! config.csv.equals(" " )) {
85
+ val unmarshalledFuture = Unmarshal (result).to[List [SearchResult ]]
86
+
87
+ val processFuture = unmarshalledFuture.transform {
88
+ case Success (unmarshalled) => {
89
+ processResults(config, unmarshalled, took)
90
+ Success (unmarshalled)
91
+ }
92
+ case Failure (e) => {
93
+ error(config)(result)
94
+ Failure (e)
95
+ }
94
96
}
95
97
}
98
+ } catch {
99
+ case e : TimeoutException => {
100
+ error(config)(" The query timed out after " + (System .nanoTime() - start).nanos.toUnit(TimeUnit .SECONDS ) +
101
+ " seconds. To set a longer timeout, use the --timeout option." )
102
+ Failure (e)
103
+ }
96
104
}
97
105
}
98
106
0 commit comments