diff --git a/src/ApiService/ApiService/Functions/Jobs.cs b/src/ApiService/ApiService/Functions/Jobs.cs index f018fd9c1..1c739e65a 100644 --- a/src/ApiService/ApiService/Functions/Jobs.cs +++ b/src/ApiService/ApiService/Functions/Jobs.cs @@ -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{ { "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)); } diff --git a/src/ApiService/ApiService/onefuzzlib/Config.cs b/src/ApiService/ApiService/onefuzzlib/Config.cs index bf89bd693..11d8bf830 100644 --- a/src/ApiService/ApiService/onefuzzlib/Config.cs +++ b/src/ApiService/ApiService/onefuzzlib/Config.cs @@ -6,7 +6,7 @@ namespace Microsoft.OneFuzz.Service; public interface IConfig { - Async.Task BuildTaskConfig(Job job, Task task); + Async.Task BuildTaskConfig(Job job, Task task); Task> CheckConfig(TaskConfig config); } @@ -49,14 +49,15 @@ public class Config : IConfig { return blobPermissions; } - public async Async.Task BuildTaskConfig(Job job, Task task) { + public async Async.Task 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]; diff --git a/src/ApiService/ApiService/onefuzzlib/Scheduler.cs b/src/ApiService/ApiService/onefuzzlib/Scheduler.cs index 8549a3f1c..b8f061314 100644 --- a/src/ApiService/ApiService/onefuzzlib/Scheduler.cs +++ b/src/ApiService/ApiService/onefuzzlib/Scheduler.cs @@ -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); } diff --git a/src/api-service/__app__/jobs/__init__.py b/src/api-service/__app__/jobs/__init__.py index db3735efd..a0df8e91d 100644 --- a/src/api-service/__app__/jobs/__init__.py +++ b/src/api-service/__app__/jobs/__init__.py @@ -3,6 +3,8 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +from uuid import uuid4 + import azure.functions as func from onefuzztypes.enums import ContainerType, ErrorCode, JobState from onefuzztypes.models import Error, JobConfig, JobTaskInfo @@ -53,9 +55,7 @@ def post(req: func.HttpRequest) -> func.HttpResponse: if isinstance(user_info, Error): return not_ok(user_info, context="jobs create") - job = Job(config=request, user_info=user_info) - job.save() - + job = Job(job_id=uuid4(), config=request, user_info=user_info) # create the job logs container log_container_sas = create_container( Container(f"logs-{job.job_id}"),