Skip to content

Commit

Permalink
feat(Backup): make restart required after backup restore
Browse files Browse the repository at this point in the history
  • Loading branch information
pkuehnel committed Feb 26, 2024
1 parent f7168c2 commit aac3f86
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
4 changes: 3 additions & 1 deletion TeslaSolarCharger/Client/Components/BackupComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

<hr />
<h2>Restore</h2>

<div class="alert alert-warning" role="alert">
After the restore process you need to restart the TSC container.
</div>
<div class="mb-2">
<MudFileUpload T="IBrowserFile" FilesChanged="SelectFile" Accept=".zip" MaximumFileCount="1">
<ButtonTemplate Context="fileUploadContext">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public class IssueKeys
public string FleetApiTokenExpired => "FleetApiTokenExpired";
public string FleetApiTokenNoApiRequestsAllowed => "FleetApiRequestsNotAllowed";
public string CrashedOnStartup => "CrashedOnStartup";
public string RestartNeeded => "RestartNeeded";
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ public PossibleIssues(IssueKeys issueKeys)
"Update TSC to the latest version."
)
},
{
issueKeys.RestartNeeded, CreateIssue("A restart is needed.",
IssueType.Error,
"Restart the TSC container.",
"Restart the Docker host."
)
},
};
}

Expand Down
6 changes: 6 additions & 0 deletions TeslaSolarCharger/Server/Scheduling/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ public JobManager(ILogger<JobManager> logger, IJobFactory jobFactory, IScheduler
public async Task StartJobs()
{
_logger.LogTrace("{Method}()", nameof(StartJobs));
if (_settings.RestartNeeded)
{
_logger.LogError("Do not start jobs as application restart is needed.");
return;
}
if (_settings.CrashedOnStartup)
{
_logger.LogError("Do not start jobs as application crashed during startup.");
return;
}
_scheduler = _schedulerFactory.GetScheduler().GetAwaiter().GetResult();
_scheduler.JobFactory = _jobFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ public async Task RestoreBackup(IFormFile file)
}
finally
{
if (jobsWereRunning)
{
await _jobManager.StartJobs().ConfigureAwait(false);
}
_settings.RestartNeeded = true;
}
}

Expand Down
5 changes: 5 additions & 0 deletions TeslaSolarCharger/Server/Services/IssueValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public async Task<List<Issue>> RefreshIssues(TimeSpan clientTimeZoneId)
{
_logger.LogTrace("{method}()", nameof(RefreshIssues));
var issueList = new List<Issue>();
if (_settings.RestartNeeded)
{
issueList.Add(_possibleIssues.GetIssueByKey(_issueKeys.RestartNeeded));
return issueList;
}
if (_settings.CrashedOnStartup)
{
var crashedOnStartupIssue = _possibleIssues.GetIssueByKey(_issueKeys.CrashedOnStartup);
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Shared/Dtos/Contracts/ISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public interface ISettings
DateTime LastFleetApiRequestAllowedCheck { get; set; }
List<DtoCar> Cars { get; set; }
List<DtoCar> CarsToManage { get; }
bool RestartNeeded { get; set; }
}
1 change: 1 addition & 0 deletions TeslaSolarCharger/Shared/Dtos/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Settings : ISettings

public bool AllowUnlimitedFleetApiRequests { get; set; }
public DateTime LastFleetApiRequestAllowedCheck { get; set; }
public bool RestartNeeded { get; set; }

public List<DtoCar> Cars { get; set; } = new();
}

0 comments on commit aac3f86

Please sign in to comment.