mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-21 13:43:01 +02:00
Start-Job endpoint: Add option to start Jobs that our job is dependent on
Some checks failed
Docker Image CI / build (push) Has been cancelled
Some checks failed
Docker Image CI / build (push) Has been cancelled
This commit is contained in:
parent
7b38d0aa2b
commit
aa67c11050
@ -5,6 +5,7 @@ using API.Schema.Jobs;
|
|||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
@ -326,6 +327,7 @@ public class JobController(PgsqlContext context, ILog Log) : Controller
|
|||||||
/// Starts the Job with the requested ID
|
/// Starts the Job with the requested ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="JobId">Job-ID</param>
|
/// <param name="JobId">Job-ID</param>
|
||||||
|
/// <param name="startDependencies">Start Jobs necessary for execution</param>
|
||||||
/// <response code="202">Job started</response>
|
/// <response code="202">Job started</response>
|
||||||
/// <response code="404">Job with ID not found</response>
|
/// <response code="404">Job with ID not found</response>
|
||||||
/// <response code="409">Job was already running</response>
|
/// <response code="409">Job was already running</response>
|
||||||
@ -335,16 +337,22 @@ public class JobController(PgsqlContext context, ILog Log) : Controller
|
|||||||
[ProducesResponseType(Status404NotFound)]
|
[ProducesResponseType(Status404NotFound)]
|
||||||
[ProducesResponseType(Status409Conflict)]
|
[ProducesResponseType(Status409Conflict)]
|
||||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||||
public IActionResult StartJob(string JobId)
|
public IActionResult StartJob(string JobId, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)]bool startDependencies = false)
|
||||||
{
|
{
|
||||||
Job? ret = context.Jobs.Find(JobId);
|
Job? ret = context.Jobs.Find(JobId);
|
||||||
if (ret is null)
|
if (ret is null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
List<Job> dependencies = startDependencies ? ret.GetDependenciesAndSelf() : [ret];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ret.state >= JobState.Running && ret.state < JobState.Completed)
|
if(dependencies.Any(d => d.state >= JobState.Running && d.state < JobState.Completed))
|
||||||
return new ConflictResult();
|
return new ConflictResult();
|
||||||
ret.LastExecution = DateTime.UnixEpoch;
|
dependencies.ForEach(d =>
|
||||||
|
{
|
||||||
|
d.LastExecution = DateTime.UnixEpoch;
|
||||||
|
d.state = JobState.CompletedWaiting;
|
||||||
|
});
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return Accepted();
|
return Accepted();
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,17 @@ public abstract class Job
|
|||||||
|
|
||||||
protected abstract IEnumerable<Job> RunInternal(PgsqlContext context);
|
protected abstract IEnumerable<Job> RunInternal(PgsqlContext context);
|
||||||
|
|
||||||
|
public List<Job> GetDependenciesAndSelf()
|
||||||
|
{
|
||||||
|
List<Job> ret = new ();
|
||||||
|
foreach (Job job in DependsOnJobs)
|
||||||
|
{
|
||||||
|
ret.AddRange(job.GetDependenciesAndSelf());
|
||||||
|
}
|
||||||
|
ret.Add(this);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{JobId}";
|
return $"{JobId}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user