Fix multiple jobs running on the same connector
Fix state-updates
Add more Documentation to JobController
Only allow non-running jobs to be started
This commit is contained in:
2025-03-03 21:13:03 +01:00
parent 8a0829ef69
commit e2ff2c76ed
3 changed files with 47 additions and 7 deletions

View File

@ -152,7 +152,7 @@ public class JobController(PgsqlContext context) : Controller
{
context.Jobs.Add(job);
context.SaveChanges();
return Created();
return new CreatedResult(job.JobId, job);
}
catch (Exception e)
{
@ -193,11 +193,15 @@ public class JobController(PgsqlContext context) : Controller
/// Starts the Job with the requested ID
/// </summary>
/// <param name="id">Job-ID</param>
/// <returns>Nothing</returns>
/// <response code="202">Job started</response>
/// <response code="404">Job with ID not found</response>
/// <response code="409">Job was already running</response>
/// <response code="500">Internal Error</response>
[HttpPost("{id}/Start")]
[ProducesResponseType(Status202Accepted)]
[ProducesResponseType(Status404NotFound)]
[ProducesResponseType(Status500InternalServerError)]
[ProducesResponseType<AcceptedResult>(Status202Accepted)]
[ProducesResponseType<NotFoundResult>(Status404NotFound)]
[ProducesResponseType<ConflictResult>(Status409Conflict)]
[ProducesResponseType<ObjectResult>(Status500InternalServerError)]
public IActionResult StartJob(string id)
{
Job? ret = context.Jobs.Find(id);
@ -205,7 +209,9 @@ public class JobController(PgsqlContext context) : Controller
return NotFound();
try
{
context.Update(ret);
if (ret.state >= JobState.Running && ret.state < JobState.Completed)
return new ConflictResult();
ret.LastExecution = DateTime.UnixEpoch;
context.SaveChanges();
return Accepted();
}
@ -215,6 +221,19 @@ public class JobController(PgsqlContext context) : Controller
}
}
/// <summary>
/// NOT IMPLEMENTED. Stops the Job with the requested ID
/// </summary>
/// <param name="id">Job-ID</param>
/// <response code="202">Job started</response>
/// <response code="404">Job with ID not found</response>
/// <response code="409">Job was not running</response>
/// <response code="500">Internal Error</response>
/// <remarks>NOT IMPLEMENTED</remarks>
[ProducesResponseType<AcceptedResult>(Status202Accepted)]
[ProducesResponseType<NotFoundResult>(Status404NotFound)]
[ProducesResponseType<ConflictResult>(Status409Conflict)]
[ProducesResponseType<ObjectResult>(Status500InternalServerError)]
[HttpPost("{id}/Stop")]
public IActionResult StopJob(string id)
{