Skip to content
Open
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
9 changes: 9 additions & 0 deletions Refund.Tests/JobQueues/ClusterQueueBatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public void ParseActiveJobs_AcceptsCommaSeparator(string line, string id, Cluste
Assert.Equal(expected, result[id]);
}

[Fact]
public void JobResourceValues_IncludeSubmittingUsername()
{
var job = new MaskJob { SubmittedByUsername = "alice" };
var values = job.GetResourceValues();

Assert.Equal("alice", values["username"]);
}

[Fact]
public void BuildWorkerScript_PreservesDollarSignsInCommand()
{
Expand Down
11 changes: 10 additions & 1 deletion Refund/DataModel/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ public abstract class Job : RelayBase, IFolderContent
[Clearable]
public User UpdatedBy { get; set; }

/// <summary>
/// Username of the user who queued/submitted this job.
/// This is included in cluster submission templates via {{username}}.
/// </summary>
[Clearable]
[RelayProperty]
public string SubmittedByUsername { get; set; } = string.Empty;

/// <summary>
/// User-provided notes or comments about this job.
/// </summary>
Expand Down Expand Up @@ -430,7 +438,8 @@ public Dictionary<string, string> GetResourceValues()
{ "gpu_memory_gb", GpuMemoryGb.ToString() },
{ "run_directory", RunDirectory },
{ "std_out", PathStdOut },
{ "std_err", PathStdErr }
{ "std_err", PathStdErr },
{ "username", SubmittedByUsername }
};
}

Expand Down
9 changes: 6 additions & 3 deletions Refund/JobQueues/ClusterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ await job.WriteToLifecycleLog(
await job.WriteToLifecycleLog($"Submitting script: {scriptPath}");

string rawOutput = null;
string jobId = await SubmitScript(scriptPath, o => rawOutput = o);
string jobId = await SubmitScript(scriptPath, o => rawOutput = o, job.SubmittedByUsername);
await job.WriteToLifecycleLog(rawOutput);
await job.WriteToLifecycleLog($"Parsed cluster job ID: {jobId}");

Expand Down Expand Up @@ -684,9 +684,12 @@ private async Task<string> PrepareAndWriteScript(Job job, Dictionary<string, str
/// Returns the cluster job ID assigned by the scheduler.
/// The raw scheduler output is returned via the optional out-style callback for logging.
/// </summary>
public async Task<string> SubmitScript(string scriptPath, Action<string> onRawOutput = null)
public async Task<string> SubmitScript(string scriptPath, Action<string> onRawOutput = null, string username = "")
{
string clusterCommand = SubmitJobTemplate.ReplaceRegex("{{\\s*script_path_abs\\s*}}", scriptPath);
string clusterCommand = SubmitJobTemplate
.ReplaceRegex("{{\\s*script_path_abs\\s*}}", scriptPath)
.ReplaceRegex("{{\\s*username\\s*}}", username ?? string.Empty);

string output = await ExecuteOnCluster(clusterCommand);
onRawOutput?.Invoke(output);
return ParseClusterJobId(output);
Expand Down
1 change: 1 addition & 0 deletions Refund/Services/Core/DataManager/DataManager.Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ await ExecuteWithLock(async () =>
{
j.Status = JobStatus.Waiting;
j.QueueId = originalQueue.Id;
j.SubmittedByUsername = user.Username;
j.AddEvent(EventType.WaitingStarted, originalUser);
});

Expand Down
3 changes: 2 additions & 1 deletion Relay/Screens/Overlay/Settings/QueueEditor.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private IEnumerable<string> GetSubmissionScriptVariables()
var variables = new List<string>
{
"command",
"username",
"job_id",
"n_processes",
"n_cores",
Expand All @@ -205,7 +206,7 @@ private IEnumerable<string> GetCommandTemplateVariables()

private IEnumerable<string> GetSubmitJobTemplateVariables()
{
return ["script_path_abs"];
return ["script_path_abs", "username"];
}

private IEnumerable<string> GetStatusJobTemplateVariables()
Expand Down