setSchedule static method

Future<Map<String, Object?>> setSchedule(
  1. Client cloudApiClient, {
  2. required String projectId,
  3. required BackupFrequency frequency,
  4. int? day,
  5. int? hour,
  6. Duration? retention,
})

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.',
  };
}