Skip to content

Commit a3e7512

Browse files
committed
Add startupRetryPeriod to VehicleRentalUpdaterConfig.
1 parent f48cc90 commit a3e7512

7 files changed

Lines changed: 57 additions & 3 deletions

File tree

application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalParameters.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ public class VehicleRentalParameters extends VehicleRentalUpdaterParameters {
99
public VehicleRentalParameters(
1010
String configRef,
1111
Duration frequency,
12+
Duration startupRetryPeriod,
1213
VehicleRentalDataSourceParameters sourceParameters
1314
) {
14-
super(configRef, frequency, sourceParameters);
15+
super(configRef, frequency, startupRetryPeriod, sourceParameters);
1516
}
1617
}

application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class VehicleRentalServiceDirectoryFetcher {
3939
VehicleRentalServiceDirectoryFetcher.class
4040
);
4141
private static final Duration DEFAULT_FREQUENCY = Duration.ofSeconds(15);
42+
private static final Duration DEFAULT_STARTUP_RETRY_PERIOD = Duration.ofSeconds(0);
4243
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
4344
.registerModule(new JavaTimeModule())
4445
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -170,6 +171,7 @@ private VehicleRentalUpdater fetchAndCreateUpdater(
170171
VehicleRentalParameters vehicleRentalParameters = new VehicleRentalParameters(
171172
"vehicle-rental-service-directory:" + parameters.network(),
172173
DEFAULT_FREQUENCY,
174+
DEFAULT_STARTUP_RETRY_PERIOD,
173175
parameters
174176
);
175177

application/src/main/java/org/opentripplanner/standalone/config/routerconfig/updaters/VehicleRentalUpdaterConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.opentripplanner.standalone.config.routerconfig.updaters;
22

33
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V1_5;
4+
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_10;
45

56
import java.time.Duration;
67
import org.opentripplanner.standalone.config.framework.json.NodeAdapter;
@@ -23,6 +24,20 @@ public static VehicleRentalUpdaterParameters create(String configRef, NodeAdapte
2324
.since(V1_5)
2425
.summary("How often the data should be updated.")
2526
.asDuration(Duration.ofMinutes(1)),
27+
c
28+
.of("startupRetryPeriod")
29+
.since(V2_10)
30+
.summary(
31+
"How long to retry loading the vehicle rental data source on startup if it initially fails."
32+
)
33+
.description(
34+
"""
35+
The first time the data source is loaded, OTP will retry for this duration every
36+
5 seconds before giving up. This is useful to handle temporary network failures during
37+
OTP startup. Set to `PT0S` to disable retries.
38+
"""
39+
)
40+
.asDuration(Duration.ofSeconds(15)),
2641
VehicleRentalSourceFactory.create(sourceType, c)
2742
);
2843
}

application/src/main/java/org/opentripplanner/updater/vehicle_rental/VehicleRentalUpdater.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.stream.Collectors;
1313
import java.util.stream.Stream;
1414
import org.opentripplanner.core.model.id.FeedScopedId;
15+
import org.opentripplanner.framework.retry.OtpRetry;
16+
import org.opentripplanner.framework.retry.OtpRetryBuilder;
1517
import org.opentripplanner.service.vehiclerental.VehicleRentalRepository;
1618
import org.opentripplanner.service.vehiclerental.model.GeofencingZone;
1719
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
@@ -46,6 +48,8 @@
4648
public class VehicleRentalUpdater extends PollingGraphUpdater {
4749

4850
private static final Logger LOG = LoggerFactory.getLogger(VehicleRentalUpdater.class);
51+
private static final Duration RETRY_INTERVAL = Duration.ofSeconds(5);
52+
private static final int RETRY_BACKOFF_MULTIPLIER = 1;
4953

5054
private final Throttle unlinkedPlaceThrottle;
5155

@@ -83,10 +87,18 @@ public VehicleRentalUpdater(
8387
// Adding a vehicle rental station service needs a graph writer runnable
8488
this.service = repository;
8589

90+
OtpRetry retry = new OtpRetryBuilder()
91+
.withName("%s updater setup".formatted(nameForLogging))
92+
.withMaxAttempts((int) parameters.startupRetryPeriod().dividedBy(RETRY_INTERVAL))
93+
.withInitialRetryInterval(RETRY_INTERVAL)
94+
.withBackoffMultiplier(RETRY_BACKOFF_MULTIPLIER)
95+
.withRetryableException(UpdaterConstructionException.class::isInstance)
96+
.build();
97+
8698
try {
8799
// Do any setup if needed
88-
source.setup();
89-
} catch (UpdaterConstructionException e) {
100+
retry.execute(source::setup);
101+
} catch (InterruptedException e) {
90102
LOG.warn("Unable to setup updater: {}", nameForLogging, e);
91103
}
92104

application/src/main/java/org/opentripplanner/updater/vehicle_rental/VehicleRentalUpdaterParameters.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ public class VehicleRentalUpdaterParameters implements PollingGraphUpdaterParame
88

99
private final String configRef;
1010
private final Duration frequency;
11+
private final Duration startupRetryPeriod;
1112
private final VehicleRentalDataSourceParameters source;
1213

1314
public VehicleRentalUpdaterParameters(
1415
String configRef,
1516
Duration frequency,
17+
Duration startupRetryPeriod,
1618
VehicleRentalDataSourceParameters source
1719
) {
1820
this.configRef = configRef;
1921
this.frequency = frequency;
22+
this.startupRetryPeriod = startupRetryPeriod;
2023
this.source = source;
2124
}
2225

@@ -33,6 +36,13 @@ public String configRef() {
3336
return configRef;
3437
}
3538

39+
/**
40+
* How long to retry loading the vehicle rental data source on startup if it initially fails.
41+
*/
42+
public Duration startupRetryPeriod() {
43+
return startupRetryPeriod;
44+
}
45+
3646
public VehicleRentalDataSourceParameters sourceParameters() {
3747
return source;
3848
}

application/src/test/java/org/opentripplanner/updater/vehicle_rental/VehicleRentalUpdaterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class VehicleRentalUpdaterTest {
3030
public static final VehicleRentalUpdaterParameters PARAMS = new VehicleRentalUpdaterParameters(
3131
"A",
3232
Duration.ofMinutes(1),
33+
Duration.ofSeconds(0),
3334
new FakeParams()
3435
);
3536
public static final DefaultVehicleRentalService SERVICE = new DefaultVehicleRentalService();

doc/user/GBFS-Config.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Furthermore, support is limited to the following form factors:
3030
| [network](#u_1_network) | `string` | The name of the network to override the one derived from the source data. | *Optional* | | 1.5 |
3131
| overloadingAllowed | `boolean` | Allow leaving vehicles at a station even though there are no free slots. | *Optional* | `false` | 2.2 |
3232
| [sourceType](#u_1_sourceType) | `enum` | What source of vehicle rental updater to use. | *Required* | | 1.5 |
33+
| [startupRetryPeriod](#u_1_startupRetryPeriod) | `duration` | How long to retry loading the vehicle rental data source on startup if it initially fails. | *Optional* | `"PT15S"` | 2.10 |
3334
| url | `string` | The URL to download the data from. | *Required* | | 1.5 |
3435
| [headers](#u_1_headers) | `map of string` | HTTP headers to add to the request. Any header key, value can be inserted. | *Optional* | | 1.5 |
3536
| [rentalPickupTypes](#u_1_rentalPickupTypes) | `enum set` | This is temporary and will be removed in a future version of OTP. Use this to specify the type of rental data that is allowed to be read from the data source. | *Optional* | | 2.7 |
@@ -84,6 +85,18 @@ GBFS feeds must include a system_id which will be used as the default `network`.
8485

8586
What source of vehicle rental updater to use.
8687

88+
<h4 id="u_1_startupRetryPeriod">startupRetryPeriod</h4>
89+
90+
**Since version:** `2.10`**Type:** `duration`**Cardinality:** `Optional`**Default value:** `"PT15S"`
91+
**Path:** /updaters/[1]
92+
93+
How long to retry loading the vehicle rental data source on startup if it initially fails.
94+
95+
The first time the data source is loaded, OTP will retry for this duration every
96+
5 seconds before giving up. This is useful to handle temporary network failures during
97+
OTP startup. Set to `PT0S` to disable retries.
98+
99+
87100
<h4 id="u_1_headers">headers</h4>
88101

89102
**Since version:** `1.5`**Type:** `map of string`**Cardinality:** `Optional`

0 commit comments

Comments
 (0)