Resolves #176 Return 409 conflict if job already exists.
This commit is contained in:
parent
28a0efe488
commit
80dc8fbe65
@ -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}");
|
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))
|
if (ContainsJobLike(job))
|
||||||
{
|
{
|
||||||
Log($"Already Contains Job {job}");
|
Log($"Already Contains Job {job}");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log($"Added {job}");
|
Log($"Added {job}");
|
||||||
this.jobs.Add(job);
|
this.jobs.Add(job);
|
||||||
UpdateJobFile(job);
|
UpdateJobFile(job);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,15 +60,22 @@ public partial class Server
|
|||||||
!TimeSpan.TryParse(intervalStr, out TimeSpan interval))
|
!TimeSpan.TryParse(intervalStr, out TimeSpan interval))
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "'interval' Parameter missing, or is not in correct format.");
|
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "'interval' Parameter missing, or is not in correct format.");
|
||||||
requestParameters.TryGetValue("language", out string? language);
|
requestParameters.TryGetValue("language", out string? language);
|
||||||
_parent.jobBoss.AddJob(new DownloadNewChapters(this, ((Manga)manga).mangaConnector, ((Manga)manga).internalId, true, interval, language));
|
return _parent.jobBoss.AddJob(new DownloadNewChapters(this, ((Manga)manga).mangaConnector,
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
((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:
|
case Job.JobType.UpdateMetaDataJob:
|
||||||
if(!requestParameters.TryGetValue("internalId", out mangaId) ||
|
if(!requestParameters.TryGetValue("internalId", out mangaId) ||
|
||||||
!_parent.TryGetPublicationById(mangaId, out manga) ||
|
!_parent.TryGetPublicationById(mangaId, out manga) ||
|
||||||
manga is null)
|
manga is null)
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "InternalId Parameter missing, or is not a valid ID.");
|
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 _parent.jobBoss.AddJob(new UpdateMetadata(this, ((Manga)manga).internalId)) switch
|
||||||
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
|
{
|
||||||
|
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.DownloadNewChaptersJob: //TODO
|
||||||
case Job.JobType.DownloadChapterJob: //TODO
|
case Job.JobType.DownloadChapterJob: //TODO
|
||||||
default: return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.MethodNotAllowed, $"JobType {Enum.GetName(jobType)} is not supported.");
|
default: return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.MethodNotAllowed, $"JobType {Enum.GetName(jobType)} is not supported.");
|
||||||
|
@ -276,7 +276,9 @@ Creates a Job.
|
|||||||
|
|
||||||
| StatusCode | Meaning |
|
| StatusCode | Meaning |
|
||||||
|------------|------------------------------------------|
|
|------------|------------------------------------------|
|
||||||
|
| 200 | Job created. |
|
||||||
| 404 | Parameter missing or could not be found. |
|
| 404 | Parameter missing or could not be found. |
|
||||||
|
| 409 | Job already exists |
|
||||||
| 500 | Error parsing interval |
|
| 500 | Error parsing interval |
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user