-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #653 from pacampbell/task_scheduling
feat: Implement a generic task scheduler
- Loading branch information
Showing
29 changed files
with
526 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Arrowgene.Ddon.Database/Files/Database/Script/migration_scheduling.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE ddon_schedule_next ( | ||
"type" INTEGER NOT NULL, | ||
"timestamp" BIGINT NOT NULL, | ||
PRIMARY KEY("type") | ||
); | ||
|
||
INSERT INTO ddon_schedule_next(type, timestamp) VALUES (19, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Arrowgene.Ddon.Shared.Model.Scheduler; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
|
||
namespace Arrowgene.Ddon.Database.Sql.Core | ||
{ | ||
public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom, TReader> | ||
where TCon : DbConnection | ||
where TCom : DbCommand | ||
where TReader : DbDataReader | ||
{ | ||
protected static readonly string[] ScheduleNextFields = new string[] | ||
{ | ||
"type", "timestamp" | ||
}; | ||
|
||
private static readonly string SqlUpdateScheduleNext = $"UPDATE \"ddon_schedule_next\" SET \"timestamp\"=@timestamp WHERE \"type\"=@type;"; | ||
private static readonly string SqlSelectScheduleNext = $"SELECT {BuildQueryField(ScheduleNextFields)} FROM \"ddon_schedule_next\";"; | ||
|
||
|
||
public Dictionary<TaskType, SchedulerTaskEntry> SelectAllTaskEntries() | ||
{ | ||
Dictionary<TaskType, SchedulerTaskEntry> results = new Dictionary<TaskType, SchedulerTaskEntry>(); | ||
ExecuteReader(SqlSelectScheduleNext, command => { }, reader => | ||
{ | ||
while (reader.Read()) | ||
{ | ||
TaskType type = (TaskType) GetUInt32(reader, "type"); | ||
results[type] = new SchedulerTaskEntry() | ||
{ | ||
Type = type, | ||
Timestamp = GetInt64(reader, "timestamp") | ||
}; | ||
} | ||
}); | ||
return results; | ||
} | ||
|
||
public bool UpdateScheduleInfo(TaskType type, long timestamp) | ||
{ | ||
return ExecuteNonQuery(SqlUpdateScheduleNext, command => | ||
{ | ||
AddParameter(command, "@type", (uint) type); | ||
AddParameter(command, "@timestamp", timestamp); | ||
}) == 1; | ||
} | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
Arrowgene.Ddon.Database/Sql/Core/Migration/00000026_TaskSchedulerMigration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Data.Common; | ||
|
||
namespace Arrowgene.Ddon.Database.Sql.Core.Migration | ||
{ | ||
public class TaskSchedulerMigration : IMigrationStrategy | ||
{ | ||
public uint From => 26; | ||
public uint To => 27; | ||
|
||
private readonly DatabaseSetting DatabaseSetting; | ||
|
||
public TaskSchedulerMigration(DatabaseSetting databaseSetting) | ||
{ | ||
DatabaseSetting = databaseSetting; | ||
} | ||
|
||
public bool Migrate(IDatabase db, DbConnection conn) | ||
{ | ||
string adaptedSchema = DdonDatabaseBuilder.GetAdaptedSchema(DatabaseSetting, "Script/migration_scheduling.sql"); | ||
db.Execute(conn, adaptedSchema); | ||
return true; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.