sync cron
This commit is contained in:
parent
7387208f69
commit
275aea422c
|
|
@ -11,9 +11,6 @@ public class CrontabItemFilter : Pagination
|
|||
[JsonPropertyName("conversation_ids")]
|
||||
public IEnumerable<string>? ConversationIds { get; set; }
|
||||
|
||||
[JsonPropertyName("titles")]
|
||||
public IEnumerable<string>? Titles { get; set; }
|
||||
|
||||
public CrontabItemFilter()
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class ScheduleTaskArgs
|
|||
public string Description { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("to_do_list")]
|
||||
public ScheduleTaskItemArgs[] Tasks { get; set; } = null!;
|
||||
public ScheduleTaskItemArgs[] Tasks { get; set; } = [];
|
||||
}
|
||||
|
||||
public class ScheduleTaskItemArgs
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public partial class FileRepository
|
|||
}
|
||||
|
||||
var cronFile = Path.Combine(baseDir, CRON_FILE);
|
||||
var json = JsonSerializer.Serialize(cronFile, _options);
|
||||
var json = JsonSerializer.Serialize(cron, _options);
|
||||
File.WriteAllText(cronFile, json);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -72,10 +72,6 @@ public partial class FileRepository
|
|||
{
|
||||
matched = matched && filter.UserIds.Contains(record.UserId);
|
||||
}
|
||||
if (filter?.Titles != null)
|
||||
{
|
||||
matched = matched && filter.Titles.Contains(record.Title);
|
||||
}
|
||||
|
||||
if (!matched) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public class CrontabItemDocument : MongoBase
|
|||
public string Cron { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public IEnumerable<CronTaskMongoElement> Tasks { get; set; } = [];
|
||||
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public static CrontabItem ToDomainModel(CrontabItemDocument item)
|
||||
|
|
@ -24,6 +25,7 @@ public class CrontabItemDocument : MongoBase
|
|||
Cron = item.Cron,
|
||||
Title = item.Title,
|
||||
Description = item.Description,
|
||||
Tasks = item.Tasks?.Select(x => CronTaskMongoElement.ToDomainElement(x))?.ToArray() ?? [],
|
||||
CreatedTime = item.CreatedTime
|
||||
};
|
||||
}
|
||||
|
|
@ -39,6 +41,7 @@ public class CrontabItemDocument : MongoBase
|
|||
Cron = item.Cron,
|
||||
Title = item.Title,
|
||||
Description = item.Description,
|
||||
Tasks = item.Tasks?.Select(x => CronTaskMongoElement.ToMongoElement(x))?.ToList() ?? [],
|
||||
CreatedTime = item.CreatedTime
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
using BotSharp.Abstraction.Crontab.Models;
|
||||
|
||||
namespace BotSharp.Plugin.MongoStorage.Models;
|
||||
|
||||
public class CronTaskMongoElement
|
||||
{
|
||||
public string Topic { get; set; }
|
||||
public string Script { get; set; }
|
||||
public string Language { get; set; }
|
||||
|
||||
public static CronTaskMongoElement ToMongoElement(ScheduleTaskItemArgs model)
|
||||
{
|
||||
return new CronTaskMongoElement
|
||||
{
|
||||
Topic = model.Topic,
|
||||
Script = model.Script,
|
||||
Language = model.Language
|
||||
};
|
||||
}
|
||||
|
||||
public static ScheduleTaskItemArgs ToDomainElement(CronTaskMongoElement model)
|
||||
{
|
||||
return new ScheduleTaskItemArgs
|
||||
{
|
||||
Topic = model.Topic,
|
||||
Script = model.Script,
|
||||
Language = model.Language
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -46,10 +46,6 @@ public partial class MongoRepository
|
|||
{
|
||||
cronFilters.Add(cronBuilder.In(x => x.ConversationId, filter.ConversationIds));
|
||||
}
|
||||
if (filter?.Titles != null)
|
||||
{
|
||||
cronFilters.Add(cronBuilder.In(x => x.Title, filter.Titles));
|
||||
}
|
||||
if (filter?.UserIds != null)
|
||||
{
|
||||
cronFilters.Add(cronBuilder.In(x => x.UserId, filter.UserIds));
|
||||
|
|
|
|||
Loading…
Reference in a new issue