Skip to content

Commit

Permalink
More Test Jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Mar 22, 2024
1 parent 9aa76a7 commit b865583
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
23 changes: 21 additions & 2 deletions Shoko.Server/API/v3/Controllers/DebugController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Shoko.Server.Providers.AniDB.Interfaces;
using Shoko.Server.Providers.AniDB.UDP.Exceptions;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs;
using Shoko.Server.Scheduling.Jobs.Test;
using Shoko.Server.Settings;

#nullable enable
Expand Down Expand Up @@ -50,7 +50,7 @@ public DebugController(ILogger<DebugController> logger, IUDPConnectionHandler ud
/// </summary>
/// <param name="count"></param>
/// <param name="seconds"></param>
[HttpGet("ScheduleTestJobs/{count}")]
[HttpGet("ScheduleJobs/Delay/{count}")]
public async Task<ActionResult> ScheduleTestJobs(int count, [FromQuery]int seconds = 60)
{
var scheduler = await _schedulerFactory.GetScheduler();
Expand All @@ -66,6 +66,25 @@ await scheduler.StartJobNow<TestDelayJob>(t =>
return Ok();
}

/// <summary>
/// Schedule {<paramref name="count"/>} jobs that just error
/// </summary>
/// <param name="count"></param>
[HttpGet("ScheduleJobs/Error/{count}")]
public async Task<ActionResult> ScheduleTestErrorJobs(int count)
{
var scheduler = await _schedulerFactory.GetScheduler();
for (var i = 0; i < count; i++)
{
await scheduler.StartJobNow<TestErrorJob>(t =>
{
t.Offset = i;
});
}

return Ok();
}

/// <summary>
/// Call the AniDB UDP API using the
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions Shoko.Server/Scheduling/Jobs/BaseJob.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using System.Xml.Serialization;
using JetBrains.Annotations;
Expand All @@ -21,8 +20,8 @@ public async Task Execute(IJobExecutionContext context)
}
catch (Exception ex)
{
_logger.LogError(ex, "Job threw an error on Execution: {Job} | Error -> {Ex}", context.JobDetail.Key, ex);
throw new JobExecutionException(msg: ex.Message, refireImmediately: false, cause: ex);
// _logger.LogError(ex, "Job threw an error on Execution: {Job} | Error -> {Ex}", context.JobDetail.Key, ex);
throw new JobExecutionException(msg: ex.Message, cause: ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Extensions.Logging;
using Shoko.Server.Scheduling.Attributes;

namespace Shoko.Server.Scheduling.Jobs;
namespace Shoko.Server.Scheduling.Jobs.Test;

[JobKeyGroup(JobKeyGroup.System)]
public class TestDelayJob : BaseJob
Expand Down
20 changes: 20 additions & 0 deletions Shoko.Server/Scheduling/Jobs/Test/TestErrorJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Shoko.Server.Scheduling.Attributes;

namespace Shoko.Server.Scheduling.Jobs.Test;

[JobKeyGroup(JobKeyGroup.System)]
public class TestErrorJob : BaseJob
{
public int Offset { get; set; }
public override string TypeName => "Test Error";
public override string Title => "Throwing an Error";

public override Task Process()
{
_logger.LogInformation("Processing {Job}", nameof(TestErrorJob));
throw new Exception("TEST TEST TEST ERROR!!!");
}
}

0 comments on commit b865583

Please sign in to comment.