Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new worker type for cloud legacy workers #181

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions OJS.Workers.Common/Models/WorkerType.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
namespace OJS.Workers.Common.Models
{
/// <summary>
/// Subset of workers on which a submission is to be executed.
/// Stored in database, so be careful with changing values.
/// </summary>
public enum WorkerType
{
Default = 0,
Legacy = 1,
Local = 2,
Alpha = 3,
LegacyCloud = 4,
}
}
5 changes: 5 additions & 0 deletions OJS.Workers.Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public static class Settings
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => x.Trim());

public static IEnumerable<string> LegacyCloudWorkerEndpoints => SettingsHelper.GetSetting("LegacyCloudWorkerEndpoints")
.Split(';')
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => x.Trim());

public static string PostgreSqlMasterDbConnectionString =>
SettingsHelper.GetSetting("PostgreSqlMasterDbConnectionString");

Expand Down
16 changes: 15 additions & 1 deletion OJS.Workers/LocalWorkerServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ private void SpawnSubmissionProcessorsAndThreads()
var localWorkerSubmissionsForProcessing = new ConcurrentQueue<TSubmission>();
var legacyWorkersSubmissionsForProcessing = new ConcurrentQueue<TSubmission>();
var alphaWorkersSubmissionsForProcessing = new ConcurrentQueue<TSubmission>();
var legacyCloudWorkersSubmissionsForProcessing = new ConcurrentQueue<TSubmission>();
var sharedLockObject = new object();

var legacyWorkerTypesList = new List<WorkerType> { WorkerType.Legacy };
var alphaWorkerTypesList = new List<WorkerType> { WorkerType.Alpha };
var localWorkerTypesList = new List<WorkerType> { WorkerType.Local };
var legacyCloudWorkerTypesList = new List<WorkerType> { WorkerType.LegacyCloud };

var isEnumParsed = Enum.TryParse(Settings.DefaultWorkerType, false, out WorkerType defaultWorkerType);
if (!isEnumParsed)
Expand All @@ -112,6 +114,9 @@ private void SpawnSubmissionProcessorsAndThreads()
case WorkerType.Local:
localWorkerTypesList.Add(WorkerType.Default);
break;
case WorkerType.LegacyCloud:
legacyCloudWorkerTypesList.Add(WorkerType.Default);
break;
default:
this.Logger.Fatal("Wrong default worker type");
throw new InvalidOperationException();
Expand All @@ -133,7 +138,8 @@ private void SpawnSubmissionProcessorsAndThreads()
workerThreads.AddRange(this.GetRemoteWorkers(
Settings.RemoteWorkerEndpoints,
legacyWorkersSubmissionsForProcessing,
sharedLockObject, formatterServiceFactory,
sharedLockObject,
formatterServiceFactory,
remoteSubmissionsFilteringService,
legacyWorkerTypesList));

Expand All @@ -145,6 +151,14 @@ private void SpawnSubmissionProcessorsAndThreads()
remoteSubmissionsFilteringService,
alphaWorkerTypesList));

workerThreads.AddRange(this.GetRemoteWorkers(
Settings.LegacyCloudWorkerEndpoints,
legacyCloudWorkersSubmissionsForProcessing,
sharedLockObject,
formatterServiceFactory,
remoteSubmissionsFilteringService,
legacyCloudWorkerTypesList));

workerThreads
.ToList()
.ForEach(workerThread =>
Expand Down