mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-22 14:19:03 +00:00
Only save the job once when creating it (#2289)
* Convert exception to warning * don't save job before creating the log container * same as the python code * test fix * format * format * don't schedule the task if the log container is missing
This commit is contained in:
@ -40,9 +40,7 @@ public class Jobs {
|
||||
UserInfo = userInfo.OkV,
|
||||
};
|
||||
|
||||
await _context.JobOperations.Insert(job);
|
||||
|
||||
// create the job logs container
|
||||
// create the job logs container
|
||||
var metadata = new Dictionary<string, string>{
|
||||
{ "container_type", "logs" }, // TODO: use ContainerType.Logs enum somehow; needs snake case name
|
||||
};
|
||||
@ -60,7 +58,7 @@ public class Jobs {
|
||||
// log container must not have the SAS included
|
||||
var logContainerUri = new UriBuilder(containerSas) { Query = "" }.Uri;
|
||||
job = job with { Config = job.Config with { Logs = logContainerUri.ToString() } };
|
||||
await _context.JobOperations.Update(job);
|
||||
await _context.JobOperations.Insert(job);
|
||||
return await RequestHandling.Ok(req, JobResponse.ForJob(job));
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ namespace Microsoft.OneFuzz.Service;
|
||||
|
||||
|
||||
public interface IConfig {
|
||||
Async.Task<TaskUnitConfig> BuildTaskConfig(Job job, Task task);
|
||||
Async.Task<TaskUnitConfig?> BuildTaskConfig(Job job, Task task);
|
||||
Task<ResultVoid<TaskConfigError>> CheckConfig(TaskConfig config);
|
||||
}
|
||||
|
||||
@ -49,14 +49,15 @@ public class Config : IConfig {
|
||||
return blobPermissions;
|
||||
}
|
||||
|
||||
public async Async.Task<TaskUnitConfig> BuildTaskConfig(Job job, Task task) {
|
||||
public async Async.Task<TaskUnitConfig?> BuildTaskConfig(Job job, Task task) {
|
||||
|
||||
if (!Defs.TASK_DEFINITIONS.ContainsKey(task.Config.Task.Type)) {
|
||||
throw new Exception($"unsupported task type: {task.Config.Task.Type}");
|
||||
}
|
||||
|
||||
if (job.Config.Logs == null) {
|
||||
throw new Exception($"Missing log container: job_id {job.JobId}, task_id {task.TaskId}");
|
||||
_logTracer.Warning($"Missing log container: job_id {job.JobId}, task_id {task.TaskId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var definition = Defs.TASK_DEFINITIONS[task.Config.Task.Type];
|
||||
|
@ -136,6 +136,10 @@ public class Scheduler : IScheduler {
|
||||
}
|
||||
|
||||
var taskConfig = await _config.BuildTaskConfig(job, task);
|
||||
if (taskConfig == null) {
|
||||
_logTracer.Info($"unable to build task config for task: {task.TaskId}");
|
||||
return null;
|
||||
}
|
||||
var setupContainer = task.Config.Containers?.FirstOrDefault(c => c.Type == ContainerType.Setup) ?? throw new Exception($"task missing setup container: task_type = {task.Config.Task.Type}");
|
||||
|
||||
var setupPs1Exist = _containers.BlobExists(setupContainer.Name, "setup.ps1", StorageType.Corpus);
|
||||
@ -177,8 +181,6 @@ public class Scheduler : IScheduler {
|
||||
setupScript,
|
||||
pool with { ETag = null });
|
||||
|
||||
|
||||
|
||||
return (bucketConfig, workUnit);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user