4 Commits

20 changed files with 1902 additions and 3 deletions

View File

@@ -0,0 +1,23 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["FictionArchive.Service.SchedulerService/FictionArchive.Service.SchedulerService.csproj", "FictionArchive.Service.SchedulerService/"]
RUN dotnet restore "FictionArchive.Service.SchedulerService/FictionArchive.Service.SchedulerService.csproj"
COPY . .
WORKDIR "/src/FictionArchive.Service.SchedulerService"
RUN dotnet build "./FictionArchive.Service.SchedulerService.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./FictionArchive.Service.SchedulerService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "FictionArchive.Service.SchedulerService.dll"]

View File

@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FictionArchive.Service.Shared\FictionArchive.Service.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AppAny.Quartz.EntityFrameworkCore.Migrations.PostgreSQL" Version="0.5.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Quartz" Version="3.15.1" />
<PackageReference Include="Quartz.AspNetCore" Version="3.15.1" />
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.15.1" />
<PackageReference Include="Quartz.Serialization.Json" Version="3.15.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,35 @@
using System.Data;
using FictionArchive.Service.SchedulerService.Models;
using FictionArchive.Service.SchedulerService.Services;
using HotChocolate.Types;
using Quartz;
namespace FictionArchive.Service.SchedulerService.GraphQL;
public class Mutation
{
[Error<DuplicateNameException>]
[Error<FormatException>]
public async Task<SchedulerJob> ScheduleEventJob(string key, string description, string eventType, string eventData, string cronSchedule, JobManagerService jobManager)
{
return await jobManager.ScheduleEventJob(key, description, eventType, eventData, cronSchedule);
}
[Error<JobPersistenceException>]
public async Task<bool> RunJob(string jobKey, JobManagerService jobManager)
{
return await jobManager.TriggerJob(jobKey);
}
[Error<KeyNotFoundException>]
public async Task<bool> DeleteJob(string jobKey, JobManagerService jobManager)
{
bool deleted = await jobManager.DeleteJob(jobKey);
if (!deleted)
{
throw new KeyNotFoundException($"Job with key '{jobKey}' was not found");
}
return true;
}
}

View File

@@ -0,0 +1,15 @@
using FictionArchive.Service.SchedulerService.Models;
using FictionArchive.Service.SchedulerService.Services;
using HotChocolate;
using Quartz;
using Quartz.Impl.Matchers;
namespace FictionArchive.Service.SchedulerService.GraphQL;
public class Query
{
public async Task<IEnumerable<SchedulerJob>> GetJobs(JobManagerService jobManager)
{
return await jobManager.GetScheduledJobs();
}
}

View File

@@ -0,0 +1,543 @@
// <auto-generated />
using FictionArchive.Service.SchedulerService.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FictionArchive.Service.SchedulerService.Migrations
{
[DbContext(typeof(SchedulerServiceDbContext))]
[Migration("20251120151130_Initial")]
partial class Initial
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.11")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzBlobTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<byte[]>("BlobData")
.HasColumnType("bytea")
.HasColumnName("blob_data");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_blob_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzCalendar", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("CalendarName")
.HasColumnType("text")
.HasColumnName("calendar_name");
b.Property<byte[]>("Calendar")
.IsRequired()
.HasColumnType("bytea")
.HasColumnName("calendar");
b.HasKey("SchedulerName", "CalendarName");
b.ToTable("qrtz_calendars", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzCronTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<string>("CronExpression")
.IsRequired()
.HasColumnType("text")
.HasColumnName("cron_expression");
b.Property<string>("TimeZoneId")
.HasColumnType("text")
.HasColumnName("time_zone_id");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_cron_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzFiredTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("EntryId")
.HasColumnType("text")
.HasColumnName("entry_id");
b.Property<long>("FiredTime")
.HasColumnType("bigint")
.HasColumnName("fired_time");
b.Property<string>("InstanceName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("instance_name");
b.Property<bool>("IsNonConcurrent")
.HasColumnType("bool")
.HasColumnName("is_nonconcurrent");
b.Property<string>("JobGroup")
.HasColumnType("text")
.HasColumnName("job_group");
b.Property<string>("JobName")
.HasColumnType("text")
.HasColumnName("job_name");
b.Property<int>("Priority")
.HasColumnType("integer")
.HasColumnName("priority");
b.Property<bool?>("RequestsRecovery")
.HasColumnType("bool")
.HasColumnName("requests_recovery");
b.Property<long>("ScheduledTime")
.HasColumnType("bigint")
.HasColumnName("sched_time");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text")
.HasColumnName("state");
b.Property<string>("TriggerGroup")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<string>("TriggerName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_name");
b.HasKey("SchedulerName", "EntryId");
b.HasIndex("InstanceName")
.HasDatabaseName("idx_qrtz_ft_trig_inst_name");
b.HasIndex("JobGroup")
.HasDatabaseName("idx_qrtz_ft_job_group");
b.HasIndex("JobName")
.HasDatabaseName("idx_qrtz_ft_job_name");
b.HasIndex("RequestsRecovery")
.HasDatabaseName("idx_qrtz_ft_job_req_recovery");
b.HasIndex("TriggerGroup")
.HasDatabaseName("idx_qrtz_ft_trig_group");
b.HasIndex("TriggerName")
.HasDatabaseName("idx_qrtz_ft_trig_name");
b.HasIndex("SchedulerName", "TriggerName", "TriggerGroup")
.HasDatabaseName("idx_qrtz_ft_trig_nm_gp");
b.ToTable("qrtz_fired_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzJobDetail", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("JobName")
.HasColumnType("text")
.HasColumnName("job_name");
b.Property<string>("JobGroup")
.HasColumnType("text")
.HasColumnName("job_group");
b.Property<string>("Description")
.HasColumnType("text")
.HasColumnName("description");
b.Property<bool>("IsDurable")
.HasColumnType("bool")
.HasColumnName("is_durable");
b.Property<bool>("IsNonConcurrent")
.HasColumnType("bool")
.HasColumnName("is_nonconcurrent");
b.Property<bool>("IsUpdateData")
.HasColumnType("bool")
.HasColumnName("is_update_data");
b.Property<string>("JobClassName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("job_class_name");
b.Property<byte[]>("JobData")
.HasColumnType("bytea")
.HasColumnName("job_data");
b.Property<bool>("RequestsRecovery")
.HasColumnType("bool")
.HasColumnName("requests_recovery");
b.HasKey("SchedulerName", "JobName", "JobGroup");
b.HasIndex("RequestsRecovery")
.HasDatabaseName("idx_qrtz_j_req_recovery");
b.ToTable("qrtz_job_details", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzLock", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("LockName")
.HasColumnType("text")
.HasColumnName("lock_name");
b.HasKey("SchedulerName", "LockName");
b.ToTable("qrtz_locks", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzPausedTriggerGroup", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.HasKey("SchedulerName", "TriggerGroup");
b.ToTable("qrtz_paused_trigger_grps", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSchedulerState", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("InstanceName")
.HasColumnType("text")
.HasColumnName("instance_name");
b.Property<long>("CheckInInterval")
.HasColumnType("bigint")
.HasColumnName("checkin_interval");
b.Property<long>("LastCheckInTime")
.HasColumnType("bigint")
.HasColumnName("last_checkin_time");
b.HasKey("SchedulerName", "InstanceName");
b.ToTable("qrtz_scheduler_state", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimplePropertyTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<bool?>("BooleanProperty1")
.HasColumnType("bool")
.HasColumnName("bool_prop_1");
b.Property<bool?>("BooleanProperty2")
.HasColumnType("bool")
.HasColumnName("bool_prop_2");
b.Property<decimal?>("DecimalProperty1")
.HasColumnType("numeric")
.HasColumnName("dec_prop_1");
b.Property<decimal?>("DecimalProperty2")
.HasColumnType("numeric")
.HasColumnName("dec_prop_2");
b.Property<int?>("IntegerProperty1")
.HasColumnType("integer")
.HasColumnName("int_prop_1");
b.Property<int?>("IntegerProperty2")
.HasColumnType("integer")
.HasColumnName("int_prop_2");
b.Property<long?>("LongProperty1")
.HasColumnType("bigint")
.HasColumnName("long_prop_1");
b.Property<long?>("LongProperty2")
.HasColumnType("bigint")
.HasColumnName("long_prop_2");
b.Property<string>("StringProperty1")
.HasColumnType("text")
.HasColumnName("str_prop_1");
b.Property<string>("StringProperty2")
.HasColumnType("text")
.HasColumnName("str_prop_2");
b.Property<string>("StringProperty3")
.HasColumnType("text")
.HasColumnName("str_prop_3");
b.Property<string>("TimeZoneId")
.HasColumnType("text")
.HasColumnName("time_zone_id");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_simprop_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimpleTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<long>("RepeatCount")
.HasColumnType("bigint")
.HasColumnName("repeat_count");
b.Property<long>("RepeatInterval")
.HasColumnType("bigint")
.HasColumnName("repeat_interval");
b.Property<long>("TimesTriggered")
.HasColumnType("bigint")
.HasColumnName("times_triggered");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_simple_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<string>("CalendarName")
.HasColumnType("text")
.HasColumnName("calendar_name");
b.Property<string>("Description")
.HasColumnType("text")
.HasColumnName("description");
b.Property<long?>("EndTime")
.HasColumnType("bigint")
.HasColumnName("end_time");
b.Property<byte[]>("JobData")
.HasColumnType("bytea")
.HasColumnName("job_data");
b.Property<string>("JobGroup")
.IsRequired()
.HasColumnType("text")
.HasColumnName("job_group");
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("job_name");
b.Property<short?>("MisfireInstruction")
.HasColumnType("smallint")
.HasColumnName("misfire_instr");
b.Property<long?>("NextFireTime")
.HasColumnType("bigint")
.HasColumnName("next_fire_time");
b.Property<long?>("PreviousFireTime")
.HasColumnType("bigint")
.HasColumnName("prev_fire_time");
b.Property<int?>("Priority")
.HasColumnType("integer")
.HasColumnName("priority");
b.Property<long>("StartTime")
.HasColumnType("bigint")
.HasColumnName("start_time");
b.Property<string>("TriggerState")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_state");
b.Property<string>("TriggerType")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_type");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.HasIndex("NextFireTime")
.HasDatabaseName("idx_qrtz_t_next_fire_time");
b.HasIndex("TriggerState")
.HasDatabaseName("idx_qrtz_t_state");
b.HasIndex("NextFireTime", "TriggerState")
.HasDatabaseName("idx_qrtz_t_nft_st");
b.HasIndex("SchedulerName", "JobName", "JobGroup");
b.ToTable("qrtz_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzBlobTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("BlobTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzCronTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("CronTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimplePropertyTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("SimplePropertyTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimpleTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("SimpleTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzJobDetail", "JobDetail")
.WithMany("Triggers")
.HasForeignKey("SchedulerName", "JobName", "JobGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("JobDetail");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzJobDetail", b =>
{
b.Navigation("Triggers");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", b =>
{
b.Navigation("BlobTriggers");
b.Navigation("CronTriggers");
b.Navigation("SimplePropertyTriggers");
b.Navigation("SimpleTriggers");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,373 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FictionArchive.Service.SchedulerService.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "quartz");
migrationBuilder.CreateTable(
name: "qrtz_calendars",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
calendar_name = table.Column<string>(type: "text", nullable: false),
calendar = table.Column<byte[]>(type: "bytea", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_calendars", x => new { x.sched_name, x.calendar_name });
});
migrationBuilder.CreateTable(
name: "qrtz_fired_triggers",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
entry_id = table.Column<string>(type: "text", nullable: false),
trigger_name = table.Column<string>(type: "text", nullable: false),
trigger_group = table.Column<string>(type: "text", nullable: false),
instance_name = table.Column<string>(type: "text", nullable: false),
fired_time = table.Column<long>(type: "bigint", nullable: false),
sched_time = table.Column<long>(type: "bigint", nullable: false),
priority = table.Column<int>(type: "integer", nullable: false),
state = table.Column<string>(type: "text", nullable: false),
job_name = table.Column<string>(type: "text", nullable: true),
job_group = table.Column<string>(type: "text", nullable: true),
is_nonconcurrent = table.Column<bool>(type: "bool", nullable: false),
requests_recovery = table.Column<bool>(type: "bool", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_fired_triggers", x => new { x.sched_name, x.entry_id });
});
migrationBuilder.CreateTable(
name: "qrtz_job_details",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
job_name = table.Column<string>(type: "text", nullable: false),
job_group = table.Column<string>(type: "text", nullable: false),
description = table.Column<string>(type: "text", nullable: true),
job_class_name = table.Column<string>(type: "text", nullable: false),
is_durable = table.Column<bool>(type: "bool", nullable: false),
is_nonconcurrent = table.Column<bool>(type: "bool", nullable: false),
is_update_data = table.Column<bool>(type: "bool", nullable: false),
requests_recovery = table.Column<bool>(type: "bool", nullable: false),
job_data = table.Column<byte[]>(type: "bytea", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_job_details", x => new { x.sched_name, x.job_name, x.job_group });
});
migrationBuilder.CreateTable(
name: "qrtz_locks",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
lock_name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_locks", x => new { x.sched_name, x.lock_name });
});
migrationBuilder.CreateTable(
name: "qrtz_paused_trigger_grps",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
trigger_group = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_paused_trigger_grps", x => new { x.sched_name, x.trigger_group });
});
migrationBuilder.CreateTable(
name: "qrtz_scheduler_state",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
instance_name = table.Column<string>(type: "text", nullable: false),
last_checkin_time = table.Column<long>(type: "bigint", nullable: false),
checkin_interval = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_scheduler_state", x => new { x.sched_name, x.instance_name });
});
migrationBuilder.CreateTable(
name: "qrtz_triggers",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
trigger_name = table.Column<string>(type: "text", nullable: false),
trigger_group = table.Column<string>(type: "text", nullable: false),
job_name = table.Column<string>(type: "text", nullable: false),
job_group = table.Column<string>(type: "text", nullable: false),
description = table.Column<string>(type: "text", nullable: true),
next_fire_time = table.Column<long>(type: "bigint", nullable: true),
prev_fire_time = table.Column<long>(type: "bigint", nullable: true),
priority = table.Column<int>(type: "integer", nullable: true),
trigger_state = table.Column<string>(type: "text", nullable: false),
trigger_type = table.Column<string>(type: "text", nullable: false),
start_time = table.Column<long>(type: "bigint", nullable: false),
end_time = table.Column<long>(type: "bigint", nullable: true),
calendar_name = table.Column<string>(type: "text", nullable: true),
misfire_instr = table.Column<short>(type: "smallint", nullable: true),
job_data = table.Column<byte[]>(type: "bytea", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_triggers", x => new { x.sched_name, x.trigger_name, x.trigger_group });
table.ForeignKey(
name: "FK_qrtz_triggers_qrtz_job_details_sched_name_job_name_job_group",
columns: x => new { x.sched_name, x.job_name, x.job_group },
principalSchema: "quartz",
principalTable: "qrtz_job_details",
principalColumns: new[] { "sched_name", "job_name", "job_group" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "qrtz_blob_triggers",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
trigger_name = table.Column<string>(type: "text", nullable: false),
trigger_group = table.Column<string>(type: "text", nullable: false),
blob_data = table.Column<byte[]>(type: "bytea", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_blob_triggers", x => new { x.sched_name, x.trigger_name, x.trigger_group });
table.ForeignKey(
name: "FK_qrtz_blob_triggers_qrtz_triggers_sched_name_trigger_name_tr~",
columns: x => new { x.sched_name, x.trigger_name, x.trigger_group },
principalSchema: "quartz",
principalTable: "qrtz_triggers",
principalColumns: new[] { "sched_name", "trigger_name", "trigger_group" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "qrtz_cron_triggers",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
trigger_name = table.Column<string>(type: "text", nullable: false),
trigger_group = table.Column<string>(type: "text", nullable: false),
cron_expression = table.Column<string>(type: "text", nullable: false),
time_zone_id = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_cron_triggers", x => new { x.sched_name, x.trigger_name, x.trigger_group });
table.ForeignKey(
name: "FK_qrtz_cron_triggers_qrtz_triggers_sched_name_trigger_name_tr~",
columns: x => new { x.sched_name, x.trigger_name, x.trigger_group },
principalSchema: "quartz",
principalTable: "qrtz_triggers",
principalColumns: new[] { "sched_name", "trigger_name", "trigger_group" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "qrtz_simple_triggers",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
trigger_name = table.Column<string>(type: "text", nullable: false),
trigger_group = table.Column<string>(type: "text", nullable: false),
repeat_count = table.Column<long>(type: "bigint", nullable: false),
repeat_interval = table.Column<long>(type: "bigint", nullable: false),
times_triggered = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_simple_triggers", x => new { x.sched_name, x.trigger_name, x.trigger_group });
table.ForeignKey(
name: "FK_qrtz_simple_triggers_qrtz_triggers_sched_name_trigger_name_~",
columns: x => new { x.sched_name, x.trigger_name, x.trigger_group },
principalSchema: "quartz",
principalTable: "qrtz_triggers",
principalColumns: new[] { "sched_name", "trigger_name", "trigger_group" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "qrtz_simprop_triggers",
schema: "quartz",
columns: table => new
{
sched_name = table.Column<string>(type: "text", nullable: false),
trigger_name = table.Column<string>(type: "text", nullable: false),
trigger_group = table.Column<string>(type: "text", nullable: false),
str_prop_1 = table.Column<string>(type: "text", nullable: true),
str_prop_2 = table.Column<string>(type: "text", nullable: true),
str_prop_3 = table.Column<string>(type: "text", nullable: true),
int_prop_1 = table.Column<int>(type: "integer", nullable: true),
int_prop_2 = table.Column<int>(type: "integer", nullable: true),
long_prop_1 = table.Column<long>(type: "bigint", nullable: true),
long_prop_2 = table.Column<long>(type: "bigint", nullable: true),
dec_prop_1 = table.Column<decimal>(type: "numeric", nullable: true),
dec_prop_2 = table.Column<decimal>(type: "numeric", nullable: true),
bool_prop_1 = table.Column<bool>(type: "bool", nullable: true),
bool_prop_2 = table.Column<bool>(type: "bool", nullable: true),
time_zone_id = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_qrtz_simprop_triggers", x => new { x.sched_name, x.trigger_name, x.trigger_group });
table.ForeignKey(
name: "FK_qrtz_simprop_triggers_qrtz_triggers_sched_name_trigger_name~",
columns: x => new { x.sched_name, x.trigger_name, x.trigger_group },
principalSchema: "quartz",
principalTable: "qrtz_triggers",
principalColumns: new[] { "sched_name", "trigger_name", "trigger_group" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "idx_qrtz_ft_job_group",
schema: "quartz",
table: "qrtz_fired_triggers",
column: "job_group");
migrationBuilder.CreateIndex(
name: "idx_qrtz_ft_job_name",
schema: "quartz",
table: "qrtz_fired_triggers",
column: "job_name");
migrationBuilder.CreateIndex(
name: "idx_qrtz_ft_job_req_recovery",
schema: "quartz",
table: "qrtz_fired_triggers",
column: "requests_recovery");
migrationBuilder.CreateIndex(
name: "idx_qrtz_ft_trig_group",
schema: "quartz",
table: "qrtz_fired_triggers",
column: "trigger_group");
migrationBuilder.CreateIndex(
name: "idx_qrtz_ft_trig_inst_name",
schema: "quartz",
table: "qrtz_fired_triggers",
column: "instance_name");
migrationBuilder.CreateIndex(
name: "idx_qrtz_ft_trig_name",
schema: "quartz",
table: "qrtz_fired_triggers",
column: "trigger_name");
migrationBuilder.CreateIndex(
name: "idx_qrtz_ft_trig_nm_gp",
schema: "quartz",
table: "qrtz_fired_triggers",
columns: new[] { "sched_name", "trigger_name", "trigger_group" });
migrationBuilder.CreateIndex(
name: "idx_qrtz_j_req_recovery",
schema: "quartz",
table: "qrtz_job_details",
column: "requests_recovery");
migrationBuilder.CreateIndex(
name: "idx_qrtz_t_next_fire_time",
schema: "quartz",
table: "qrtz_triggers",
column: "next_fire_time");
migrationBuilder.CreateIndex(
name: "idx_qrtz_t_nft_st",
schema: "quartz",
table: "qrtz_triggers",
columns: new[] { "next_fire_time", "trigger_state" });
migrationBuilder.CreateIndex(
name: "idx_qrtz_t_state",
schema: "quartz",
table: "qrtz_triggers",
column: "trigger_state");
migrationBuilder.CreateIndex(
name: "IX_qrtz_triggers_sched_name_job_name_job_group",
schema: "quartz",
table: "qrtz_triggers",
columns: new[] { "sched_name", "job_name", "job_group" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "qrtz_blob_triggers",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_calendars",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_cron_triggers",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_fired_triggers",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_locks",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_paused_trigger_grps",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_scheduler_state",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_simple_triggers",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_simprop_triggers",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_triggers",
schema: "quartz");
migrationBuilder.DropTable(
name: "qrtz_job_details",
schema: "quartz");
}
}
}

View File

@@ -0,0 +1,540 @@
// <auto-generated />
using FictionArchive.Service.SchedulerService.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FictionArchive.Service.SchedulerService.Migrations
{
[DbContext(typeof(SchedulerServiceDbContext))]
partial class SchedulerServiceDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.11")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzBlobTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<byte[]>("BlobData")
.HasColumnType("bytea")
.HasColumnName("blob_data");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_blob_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzCalendar", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("CalendarName")
.HasColumnType("text")
.HasColumnName("calendar_name");
b.Property<byte[]>("Calendar")
.IsRequired()
.HasColumnType("bytea")
.HasColumnName("calendar");
b.HasKey("SchedulerName", "CalendarName");
b.ToTable("qrtz_calendars", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzCronTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<string>("CronExpression")
.IsRequired()
.HasColumnType("text")
.HasColumnName("cron_expression");
b.Property<string>("TimeZoneId")
.HasColumnType("text")
.HasColumnName("time_zone_id");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_cron_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzFiredTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("EntryId")
.HasColumnType("text")
.HasColumnName("entry_id");
b.Property<long>("FiredTime")
.HasColumnType("bigint")
.HasColumnName("fired_time");
b.Property<string>("InstanceName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("instance_name");
b.Property<bool>("IsNonConcurrent")
.HasColumnType("bool")
.HasColumnName("is_nonconcurrent");
b.Property<string>("JobGroup")
.HasColumnType("text")
.HasColumnName("job_group");
b.Property<string>("JobName")
.HasColumnType("text")
.HasColumnName("job_name");
b.Property<int>("Priority")
.HasColumnType("integer")
.HasColumnName("priority");
b.Property<bool?>("RequestsRecovery")
.HasColumnType("bool")
.HasColumnName("requests_recovery");
b.Property<long>("ScheduledTime")
.HasColumnType("bigint")
.HasColumnName("sched_time");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text")
.HasColumnName("state");
b.Property<string>("TriggerGroup")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<string>("TriggerName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_name");
b.HasKey("SchedulerName", "EntryId");
b.HasIndex("InstanceName")
.HasDatabaseName("idx_qrtz_ft_trig_inst_name");
b.HasIndex("JobGroup")
.HasDatabaseName("idx_qrtz_ft_job_group");
b.HasIndex("JobName")
.HasDatabaseName("idx_qrtz_ft_job_name");
b.HasIndex("RequestsRecovery")
.HasDatabaseName("idx_qrtz_ft_job_req_recovery");
b.HasIndex("TriggerGroup")
.HasDatabaseName("idx_qrtz_ft_trig_group");
b.HasIndex("TriggerName")
.HasDatabaseName("idx_qrtz_ft_trig_name");
b.HasIndex("SchedulerName", "TriggerName", "TriggerGroup")
.HasDatabaseName("idx_qrtz_ft_trig_nm_gp");
b.ToTable("qrtz_fired_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzJobDetail", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("JobName")
.HasColumnType("text")
.HasColumnName("job_name");
b.Property<string>("JobGroup")
.HasColumnType("text")
.HasColumnName("job_group");
b.Property<string>("Description")
.HasColumnType("text")
.HasColumnName("description");
b.Property<bool>("IsDurable")
.HasColumnType("bool")
.HasColumnName("is_durable");
b.Property<bool>("IsNonConcurrent")
.HasColumnType("bool")
.HasColumnName("is_nonconcurrent");
b.Property<bool>("IsUpdateData")
.HasColumnType("bool")
.HasColumnName("is_update_data");
b.Property<string>("JobClassName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("job_class_name");
b.Property<byte[]>("JobData")
.HasColumnType("bytea")
.HasColumnName("job_data");
b.Property<bool>("RequestsRecovery")
.HasColumnType("bool")
.HasColumnName("requests_recovery");
b.HasKey("SchedulerName", "JobName", "JobGroup");
b.HasIndex("RequestsRecovery")
.HasDatabaseName("idx_qrtz_j_req_recovery");
b.ToTable("qrtz_job_details", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzLock", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("LockName")
.HasColumnType("text")
.HasColumnName("lock_name");
b.HasKey("SchedulerName", "LockName");
b.ToTable("qrtz_locks", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzPausedTriggerGroup", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.HasKey("SchedulerName", "TriggerGroup");
b.ToTable("qrtz_paused_trigger_grps", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSchedulerState", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("InstanceName")
.HasColumnType("text")
.HasColumnName("instance_name");
b.Property<long>("CheckInInterval")
.HasColumnType("bigint")
.HasColumnName("checkin_interval");
b.Property<long>("LastCheckInTime")
.HasColumnType("bigint")
.HasColumnName("last_checkin_time");
b.HasKey("SchedulerName", "InstanceName");
b.ToTable("qrtz_scheduler_state", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimplePropertyTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<bool?>("BooleanProperty1")
.HasColumnType("bool")
.HasColumnName("bool_prop_1");
b.Property<bool?>("BooleanProperty2")
.HasColumnType("bool")
.HasColumnName("bool_prop_2");
b.Property<decimal?>("DecimalProperty1")
.HasColumnType("numeric")
.HasColumnName("dec_prop_1");
b.Property<decimal?>("DecimalProperty2")
.HasColumnType("numeric")
.HasColumnName("dec_prop_2");
b.Property<int?>("IntegerProperty1")
.HasColumnType("integer")
.HasColumnName("int_prop_1");
b.Property<int?>("IntegerProperty2")
.HasColumnType("integer")
.HasColumnName("int_prop_2");
b.Property<long?>("LongProperty1")
.HasColumnType("bigint")
.HasColumnName("long_prop_1");
b.Property<long?>("LongProperty2")
.HasColumnType("bigint")
.HasColumnName("long_prop_2");
b.Property<string>("StringProperty1")
.HasColumnType("text")
.HasColumnName("str_prop_1");
b.Property<string>("StringProperty2")
.HasColumnType("text")
.HasColumnName("str_prop_2");
b.Property<string>("StringProperty3")
.HasColumnType("text")
.HasColumnName("str_prop_3");
b.Property<string>("TimeZoneId")
.HasColumnType("text")
.HasColumnName("time_zone_id");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_simprop_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimpleTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<long>("RepeatCount")
.HasColumnType("bigint")
.HasColumnName("repeat_count");
b.Property<long>("RepeatInterval")
.HasColumnType("bigint")
.HasColumnName("repeat_interval");
b.Property<long>("TimesTriggered")
.HasColumnType("bigint")
.HasColumnName("times_triggered");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.ToTable("qrtz_simple_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", b =>
{
b.Property<string>("SchedulerName")
.HasColumnType("text")
.HasColumnName("sched_name");
b.Property<string>("TriggerName")
.HasColumnType("text")
.HasColumnName("trigger_name");
b.Property<string>("TriggerGroup")
.HasColumnType("text")
.HasColumnName("trigger_group");
b.Property<string>("CalendarName")
.HasColumnType("text")
.HasColumnName("calendar_name");
b.Property<string>("Description")
.HasColumnType("text")
.HasColumnName("description");
b.Property<long?>("EndTime")
.HasColumnType("bigint")
.HasColumnName("end_time");
b.Property<byte[]>("JobData")
.HasColumnType("bytea")
.HasColumnName("job_data");
b.Property<string>("JobGroup")
.IsRequired()
.HasColumnType("text")
.HasColumnName("job_group");
b.Property<string>("JobName")
.IsRequired()
.HasColumnType("text")
.HasColumnName("job_name");
b.Property<short?>("MisfireInstruction")
.HasColumnType("smallint")
.HasColumnName("misfire_instr");
b.Property<long?>("NextFireTime")
.HasColumnType("bigint")
.HasColumnName("next_fire_time");
b.Property<long?>("PreviousFireTime")
.HasColumnType("bigint")
.HasColumnName("prev_fire_time");
b.Property<int?>("Priority")
.HasColumnType("integer")
.HasColumnName("priority");
b.Property<long>("StartTime")
.HasColumnType("bigint")
.HasColumnName("start_time");
b.Property<string>("TriggerState")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_state");
b.Property<string>("TriggerType")
.IsRequired()
.HasColumnType("text")
.HasColumnName("trigger_type");
b.HasKey("SchedulerName", "TriggerName", "TriggerGroup");
b.HasIndex("NextFireTime")
.HasDatabaseName("idx_qrtz_t_next_fire_time");
b.HasIndex("TriggerState")
.HasDatabaseName("idx_qrtz_t_state");
b.HasIndex("NextFireTime", "TriggerState")
.HasDatabaseName("idx_qrtz_t_nft_st");
b.HasIndex("SchedulerName", "JobName", "JobGroup");
b.ToTable("qrtz_triggers", "quartz");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzBlobTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("BlobTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzCronTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("CronTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimplePropertyTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("SimplePropertyTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzSimpleTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", "Trigger")
.WithMany("SimpleTriggers")
.HasForeignKey("SchedulerName", "TriggerName", "TriggerGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Trigger");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", b =>
{
b.HasOne("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzJobDetail", "JobDetail")
.WithMany("Triggers")
.HasForeignKey("SchedulerName", "JobName", "JobGroup")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("JobDetail");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzJobDetail", b =>
{
b.Navigation("Triggers");
});
modelBuilder.Entity("AppAny.Quartz.EntityFrameworkCore.Migrations.QuartzTrigger", b =>
{
b.Navigation("BlobTriggers");
b.Navigation("CronTriggers");
b.Navigation("SimplePropertyTriggers");
b.Navigation("SimpleTriggers");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,35 @@
using FictionArchive.Service.Shared.Services.EventBus;
using Newtonsoft.Json;
using Quartz;
namespace FictionArchive.Service.SchedulerService.Models.JobTemplates;
public class EventJobTemplate : IJob
{
private readonly IEventBus _eventBus;
private readonly ILogger<EventJobTemplate> _logger;
public const string EventTypeParameter = "RoutingKey";
public const string EventDataParameter = "MessageData";
public EventJobTemplate(IEventBus eventBus, ILogger<EventJobTemplate> logger)
{
_eventBus = eventBus;
_logger = logger;
}
public async Task Execute(IJobExecutionContext context)
{
try
{
var eventData = context.MergedJobDataMap.GetString(EventDataParameter);
var eventType = context.MergedJobDataMap.GetString(EventTypeParameter);
var eventObject = JsonConvert.DeserializeObject(eventData);
await _eventBus.Publish(eventObject, eventType);
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while running an event job.");
}
}
}

View File

@@ -0,0 +1,12 @@
using Quartz;
namespace FictionArchive.Service.SchedulerService.Models;
public class SchedulerJob
{
public JobKey JobKey { get; set; }
public string Description { get; set; }
public string JobTypeName { get; set; }
public List<string> CronSchedule { get; set; }
public Dictionary<string, string> JobData { get; set; }
}

View File

@@ -0,0 +1,74 @@
using FictionArchive.Service.SchedulerService.GraphQL;
using FictionArchive.Service.SchedulerService.Services;
using FictionArchive.Service.Shared.Extensions;
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
using Quartz;
using Quartz.Impl.AdoJobStore;
namespace FictionArchive.Service.SchedulerService;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Services
builder.Services.AddDefaultGraphQl<Query, Mutation>();
builder.Services.AddHealthChecks();
builder.Services.AddTransient<JobManagerService>();
#region Database
builder.Services.RegisterDbContext<SchedulerServiceDbContext>(builder.Configuration.GetConnectionString("DefaultConnection"));
#endregion
#region Event Bus
builder.Services.AddRabbitMQ(opt =>
{
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
});
#endregion
#region Quartz
builder.Services.AddQuartz(opt =>
{
opt.UsePersistentStore(pso =>
{
pso.UsePostgres(pgsql =>
{
pgsql.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection");
pgsql.UseDriverDelegate<PostgreSQLDelegate>();
pgsql.TablePrefix = "quartz.qrtz_"; // Needed for Postgres due to the differing schema used
});
pso.UseNewtonsoftJsonSerializer();
});
});
builder.Services.AddQuartzHostedService(opt =>
{
opt.WaitForJobsToComplete = true;
});
#endregion
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<SchedulerServiceDbContext>();
dbContext.UpdateDatabase();
}
app.UseHttpsRedirection();
app.MapHealthChecks("/healthz");
app.MapGraphQL();
app.Run();
}
}

View File

@@ -0,0 +1,39 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61312",
"sslPort": 44365
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5213",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "graphql",
"applicationUrl": "https://localhost:7145;http://localhost:5213",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,99 @@
using System.Data;
using FictionArchive.Service.SchedulerService.Models;
using FictionArchive.Service.SchedulerService.Models.JobTemplates;
using FictionArchive.Service.Shared.Services.EventBus;
using Quartz;
using Quartz.Impl.Matchers;
namespace FictionArchive.Service.SchedulerService.Services;
public class JobManagerService
{
private readonly ILogger<JobManagerService> _logger;
private readonly ISchedulerFactory _schedulerFactory;
public JobManagerService(ILogger<JobManagerService> logger, ISchedulerFactory schedulerFactory)
{
_logger = logger;
_schedulerFactory = schedulerFactory;
}
public async Task<List<SchedulerJob>> GetScheduledJobs()
{
var scheduler = await _schedulerFactory.GetScheduler();
var groups = await scheduler.GetJobGroupNames();
var result = new List<(IJobDetail Job, IReadOnlyCollection<ITrigger> Triggers)>();
foreach (var group in groups)
{
var jobKeys = await scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals(group));
foreach (var jobKey in jobKeys)
{
var jobDetail = await scheduler.GetJobDetail(jobKey);
var triggers = await scheduler.GetTriggersOfJob(jobKey);
result.Add((jobDetail, triggers));
}
}
return result.Select(tuple => new SchedulerJob()
{
JobKey = tuple.Job.Key,
Description = tuple.Job.Description,
JobTypeName = tuple.Job.JobType.FullName,
JobData = tuple.Job.JobDataMap.ToDictionary(kv => kv.Key, kv => kv.Value.ToString()),
CronSchedule = tuple.Triggers.Where(trigger => trigger is ICronTrigger).Select(trigger => (trigger as ICronTrigger).CronExpressionString).ToList()
}).ToList();
}
public async Task<SchedulerJob> ScheduleEventJob(string? jobKey, string? description, string eventType, string eventData, string cronSchedule)
{
var scheduler = await _schedulerFactory.GetScheduler();
if (await scheduler.GetJobDetail(new JobKey(jobKey)) != null)
{
throw new DuplicateNameException("A job with the same key already exists.");
}
jobKey ??= Guid.NewGuid().ToString();
var jobData = new JobDataMap
{
{ EventJobTemplate.EventTypeParameter, eventType },
{ EventJobTemplate.EventDataParameter, eventData }
};
var job = JobBuilder.Create<EventJobTemplate>()
.WithIdentity(jobKey)
.WithDescription(description ?? $"Fires off an event on a set schedule")
.SetJobData(jobData)
.Build();
var trigger = TriggerBuilder.Create()
.WithIdentity(jobKey)
.WithCronSchedule(cronSchedule)
.StartNow()
.Build();
await scheduler.ScheduleJob(job, trigger);
return new SchedulerJob()
{
CronSchedule = new List<string> { cronSchedule },
Description = description,
JobKey = new JobKey(jobKey),
JobTypeName = typeof(EventJobTemplate).FullName,
JobData = jobData.ToDictionary(kv => kv.Key, kv => kv.Value.ToString())
};
}
public async Task<bool> TriggerJob(string jobKey)
{
var scheduler = await _schedulerFactory.GetScheduler();
await scheduler.TriggerJob(new JobKey(jobKey));
return true;
}
public async Task<bool> DeleteJob(string jobKey)
{
var scheduler = await _schedulerFactory.GetScheduler();
return await scheduler.DeleteJob(new JobKey(jobKey));
}
}

View File

@@ -0,0 +1,19 @@
using AppAny.Quartz.EntityFrameworkCore.Migrations;
using AppAny.Quartz.EntityFrameworkCore.Migrations.PostgreSQL;
using FictionArchive.Service.Shared.Services.Database;
using Microsoft.EntityFrameworkCore;
namespace FictionArchive.Service.SchedulerService.Services;
public class SchedulerServiceDbContext : FictionArchiveDbContext
{
public SchedulerServiceDbContext(DbContextOptions options, ILogger<SchedulerServiceDbContext> logger) : base(options, logger)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.AddQuartz(builder => builder.UsePostgreSql());
base.OnModelCreating(modelBuilder);
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,16 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"RabbitMQ": {
"ConnectionString": "amqp://localhost",
"ClientIdentifier": "SchedulerService"
},
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=FictionArchive_SchedulerService;Username=postgres;password=postgres"
},
"AllowedHosts": "*"
}

View File

@@ -13,6 +13,7 @@ public static class GraphQLExtensions
.AddQueryType<TQuery>() .AddQueryType<TQuery>()
.AddMutationType<TMutation>() .AddMutationType<TMutation>()
.AddDiagnosticEventListener<ErrorEventListener>() .AddDiagnosticEventListener<ErrorEventListener>()
.AddErrorFilter<LoggingErrorFilter>()
.AddType<UnsignedIntType>() .AddType<UnsignedIntType>()
.AddType<InstantType>() .AddType<InstantType>()
.AddMutationConventions(applyToAllMutations: true) .AddMutationConventions(applyToAllMutations: true)

View File

@@ -3,4 +3,5 @@ namespace FictionArchive.Service.Shared.Services.EventBus;
public interface IEventBus public interface IEventBus
{ {
Task Publish<TEvent>(TEvent integrationEvent) where TEvent : IntegrationEvent; Task Publish<TEvent>(TEvent integrationEvent) where TEvent : IntegrationEvent;
Task Publish(object integrationEvent, string eventType);
} }

View File

@@ -36,15 +36,20 @@ public class RabbitMQEventBus : IEventBus, IHostedService
public async Task Publish<TEvent>(TEvent integrationEvent) where TEvent : IntegrationEvent public async Task Publish<TEvent>(TEvent integrationEvent) where TEvent : IntegrationEvent
{ {
var routingKey = typeof(TEvent).Name; var routingKey = typeof(TEvent).Name;
var channel = await _connectionProvider.GetDefaultChannelAsync();
// Set integration event values // Set integration event values
integrationEvent.CreatedAt = Instant.FromDateTimeUtc(DateTime.UtcNow); integrationEvent.CreatedAt = Instant.FromDateTimeUtc(DateTime.UtcNow);
integrationEvent.EventId = Guid.NewGuid(); integrationEvent.EventId = Guid.NewGuid();
await Publish(integrationEvent, routingKey);
}
public async Task Publish(object integrationEvent, string eventType)
{
var channel = await _connectionProvider.GetDefaultChannelAsync();
var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(integrationEvent)); var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(integrationEvent));
await channel.BasicPublishAsync(ExchangeName, routingKey, true, body); await channel.BasicPublishAsync(ExchangeName, eventType, true, body);
_logger.LogInformation("Published event {EventName}", routingKey); _logger.LogInformation("Published event {EventName}", eventType);
} }
public async Task StartAsync(CancellationToken cancellationToken) public async Task StartAsync(CancellationToken cancellationToken)

View File

@@ -0,0 +1,23 @@
using Microsoft.Extensions.Logging;
namespace FictionArchive.Service.Shared.Services.GraphQL;
public class LoggingErrorFilter : IErrorFilter
{
private readonly ILogger<LoggingErrorFilter> _logger;
public LoggingErrorFilter(ILogger<LoggingErrorFilter> logger)
{
_logger = logger;
}
public IError OnError(IError error)
{
if (error.Exception != null)
{
_logger.LogError(error.Exception, "Unexpected GraphQL error occurred");
}
return error;
}
}

View File

@@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.Tran
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.Shared", "FictionArchive.Service.Shared\FictionArchive.Service.Shared.csproj", "{82638874-304C-43E6-8EFA-8AD4C41C4435}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.Shared", "FictionArchive.Service.Shared\FictionArchive.Service.Shared.csproj", "{82638874-304C-43E6-8EFA-8AD4C41C4435}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.SchedulerService", "FictionArchive.Service.SchedulerService\FictionArchive.Service.SchedulerService.csproj", "{6813A8AD-A071-4F86-B227-BC4A5BCD7F3C}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -36,5 +38,9 @@ Global
{82638874-304C-43E6-8EFA-8AD4C41C4435}.Debug|Any CPU.Build.0 = Debug|Any CPU {82638874-304C-43E6-8EFA-8AD4C41C4435}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82638874-304C-43E6-8EFA-8AD4C41C4435}.Release|Any CPU.ActiveCfg = Release|Any CPU {82638874-304C-43E6-8EFA-8AD4C41C4435}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82638874-304C-43E6-8EFA-8AD4C41C4435}.Release|Any CPU.Build.0 = Release|Any CPU {82638874-304C-43E6-8EFA-8AD4C41C4435}.Release|Any CPU.Build.0 = Release|Any CPU
{6813A8AD-A071-4F86-B227-BC4A5BCD7F3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6813A8AD-A071-4F86-B227-BC4A5BCD7F3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6813A8AD-A071-4F86-B227-BC4A5BCD7F3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6813A8AD-A071-4F86-B227-BC4A5BCD7F3C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal