tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
RemoteDeploymentManagerFactory.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Concurrent;
3using System.Collections.Generic;
4
5using Microsoft.Extensions.Logging;
6
11
13{
16 {
21
26
31
35 readonly ILoggerFactory loggerFactory;
36
40 readonly ILogger<RemoteDeploymentManagerFactory> logger;
41
45 readonly ConcurrentDictionary<long, Action<bool>> activationCallbacks;
46
59 ILoggerFactory loggerFactory,
60 ILogger<RemoteDeploymentManagerFactory> logger)
61 {
62 this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
63 this.gitHubServiceFactory = gitHubServiceFactory ?? throw new ArgumentNullException(nameof(gitHubServiceFactory));
64 this.gitRemoteFeaturesFactory = gitRemoteFeaturesFactory ?? throw new ArgumentNullException(nameof(gitRemoteFeaturesFactory));
65 this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
66 this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
67
68 activationCallbacks = new ConcurrentDictionary<long, Action<bool>>();
69 }
70
72 public IRemoteDeploymentManager CreateRemoteDeploymentManager(Api.Models.Instance metadata, RemoteGitProvider remoteGitProvider)
73 {
74 ArgumentNullException.ThrowIfNull(metadata);
75
76 logger.LogTrace("Creating remote deployment manager for remote git provider {remoteGitProvider}...", remoteGitProvider);
77 return remoteGitProvider switch
78 {
79 RemoteGitProvider.GitHub => new GitHubRemoteDeploymentManager(
83 metadata,
85 RemoteGitProvider.GitLab => new GitLabRemoteDeploymentManager(
87 metadata,
89 RemoteGitProvider.Unknown => new NoOpRemoteDeploymentManager(
91 metadata,
93 _ => throw new InvalidOperationException($"Invalid RemoteGitProvider: {remoteGitProvider}!"),
94 };
95 }
96
98 public IRemoteDeploymentManager CreateRemoteDeploymentManager(Api.Models.Instance metadata, Models.CompileJob compileJob)
99 {
100 ArgumentNullException.ThrowIfNull(compileJob);
101
102 RemoteGitProvider remoteGitProvider;
103
104 // Pre 4.7.X
105 if (compileJob.RepositoryOrigin == null)
106 remoteGitProvider = RemoteGitProvider.Unknown;
107 else
109 new Uri(
110 compileJob.RepositoryOrigin));
111
112 return CreateRemoteDeploymentManager(metadata, remoteGitProvider);
113 }
114
116 public void ForgetLocalStateForCompileJobs(IEnumerable<long> compileJobIds)
117 {
118 ArgumentNullException.ThrowIfNull(compileJobIds);
119
120 foreach (var compileJobId in compileJobIds)
121 activationCallbacks.Remove(compileJobId, out _);
122 }
123 }
124}
void ForgetLocalStateForCompileJobs(IEnumerable< long > compileJobIds)
Cause the IRemoteDeploymentManagerFactory to drop any local state is has for the given compileJobsIds...
RemoteDeploymentManagerFactory(IDatabaseContextFactory databaseContextFactory, IGitHubServiceFactory gitHubServiceFactory, IGitRemoteFeaturesFactory gitRemoteFeaturesFactory, ILoggerFactory loggerFactory, ILogger< RemoteDeploymentManagerFactory > logger)
Initializes a new instance of the RemoteDeploymentManagerFactory class.
readonly ILogger< RemoteDeploymentManagerFactory > logger
The IDatabaseContextFactory for the RemoteDeploymentManagerFactory.
readonly IGitRemoteFeaturesFactory gitRemoteFeaturesFactory
The IGitRemoteFeaturesFactory for the RemoteDeploymentManagerFactory.
readonly ConcurrentDictionary< long, Action< bool > > activationCallbacks
A map of Models.CompileJob EntityId.Ids to activation callback Action<T1>s.
readonly IGitHubServiceFactory gitHubServiceFactory
The IDatabaseContextFactory for the RemoteDeploymentManagerFactory.
readonly IDatabaseContextFactory databaseContextFactory
The IDatabaseContextFactory for the RemoteDeploymentManagerFactory.
IRemoteDeploymentManager CreateRemoteDeploymentManager(Api.Models.Instance metadata, Models.CompileJob compileJob)
Create a IRemoteDeploymentManager for a given compileJob .A new IRemoteDeploymentManager.
readonly ILoggerFactory loggerFactory
The IDatabaseContextFactory for the RemoteDeploymentManagerFactory.
IRemoteDeploymentManager CreateRemoteDeploymentManager(Api.Models.Instance metadata, RemoteGitProvider remoteGitProvider)
Creates a IRemoteDeploymentManager for a given remoteGitProvider .A new IRemoteDeploymentManager base...
RemoteGitProvider ParseRemoteGitProviderFromOrigin(Uri origin)
Gets the RemoteGitProvider for a given origin .
Factory for scoping usage of IDatabaseContexts. Meant for use by Components.
RemoteGitProvider
Indicates the remote git host.