2
0

Resolves #176 Return 409 conflict if job already exists.

This commit is contained in:
Glax 2024-04-25 23:50:06 +02:00
parent 28a0efe488
commit 80dc8fbe65
3 changed files with 16 additions and 5 deletions

View File

@ -17,17 +17,19 @@ public class JobBoss : GlobalBase
Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}");
}
public void AddJob(Job job)
public bool AddJob(Job job)
{
if (ContainsJobLike(job))
{
Log($"Already Contains Job {job}");
return false;
}
else
{
Log($"Added {job}");
this.jobs.Add(job);
UpdateJobFile(job);
return true;
}
}

View File

@ -60,15 +60,22 @@ public partial class Server
!TimeSpan.TryParse(intervalStr, out TimeSpan interval))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "'interval' Parameter missing, or is not in correct format.");
requestParameters.TryGetValue("language", out string? language);
_parent.jobBoss.AddJob(new DownloadNewChapters(this, ((Manga)manga).mangaConnector, ((Manga)manga).internalId, true, interval, language));
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
return _parent.jobBoss.AddJob(new DownloadNewChapters(this, ((Manga)manga).mangaConnector,
((Manga)manga).internalId, true, interval, language)) switch
{
true => new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null),
false => new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.Conflict, "Job already exists."),
};
case Job.JobType.UpdateMetaDataJob:
if(!requestParameters.TryGetValue("internalId", out mangaId) ||
!_parent.TryGetPublicationById(mangaId, out manga) ||
manga is null)
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "InternalId Parameter missing, or is not a valid ID.");
_parent.jobBoss.AddJob(new UpdateMetadata(this, ((Manga)manga).internalId));
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
return _parent.jobBoss.AddJob(new UpdateMetadata(this, ((Manga)manga).internalId)) switch
{
true => new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null),
false => new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.Conflict, "Job already exists."),
};
case Job.JobType.DownloadNewChaptersJob: //TODO
case Job.JobType.DownloadChapterJob: //TODO
default: return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.MethodNotAllowed, $"JobType {Enum.GetName(jobType)} is not supported.");

View File

@ -276,7 +276,9 @@ Creates a Job.
| StatusCode | Meaning |
|------------|------------------------------------------|
| 200 | Job created. |
| 404 | Parameter missing or could not be found. |
| 409 | Job already exists |
| 500 | Error parsing interval |
</details>