setSchedule static method
Sets the automated backup schedule of the project's database.
Throws FailureException if the project's plan does not include database backups, or if the request fails.
Implementation
static Future<Map<String, Object?>> setSchedule(
final Client cloudApiClient, {
required final String projectId,
required final BackupFrequency frequency,
final int? day,
final int? hour,
final Duration? retention,
}) async {
final effectiveHour = hour ?? 0;
final effectiveDay = switch (frequency) {
BackupFrequency.daily => null,
BackupFrequency.weekly || BackupFrequency.monthly => day ?? 1,
};
try {
await cloudApiClient.database.setBackupSchedule(
cloudCapsuleId: projectId,
frequency: frequency,
day: effectiveDay,
hour: effectiveHour,
retention: retention,
);
} on ProcurementDeniedException catch (e, s) {
throw _backupDeniedFailure(e, s, projectId: projectId);
} on Exception catch (e, s) {
throw FailureException.nested(e, s, 'Failed to set backup schedule');
}
return {
'projectId': projectId,
'frequency': frequency,
'day': effectiveDay,
'hour': effectiveHour,
'retention': retention,
if (frequency == BackupFrequency.daily && day != null)
'warning':
'A day is not applicable to a daily schedule and is ignored.',
};
}