temp save
This commit is contained in:
parent
eac490e8ed
commit
0de06a9297
|
|
@ -2,9 +2,6 @@ namespace BotSharp.Abstraction.Crontab.Models;
|
|||
|
||||
public class CrontabItem : ScheduleTaskArgs
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonPropertyName("user_id")]
|
||||
public string UserId { get; set; } = null!;
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
#endregion
|
||||
|
||||
#region Crontab
|
||||
bool InsertCrontabItem(CrontabItem item) => throw new NotImplementedException();
|
||||
bool InsertCrontabItem(CrontabItem cron) => throw new NotImplementedException();
|
||||
PagedItems<CrontabItem> GetCrontabItems(CrontabItemFilter filter) => throw new NotImplementedException();
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,30 +4,24 @@ namespace BotSharp.Core.Repository;
|
|||
|
||||
public partial class FileRepository
|
||||
{
|
||||
public bool InsertCrontabItem(CrontabItem item)
|
||||
public bool InsertCrontabItem(CrontabItem cron)
|
||||
{
|
||||
if (item == null)
|
||||
if (cron == null || string.IsNullOrWhiteSpace(cron.ConversationId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var baseDir = Path.Combine(_dbSettings.FileRepository, CRONTAB_FOLDER);
|
||||
item.Id = Guid.NewGuid().ToString();
|
||||
var dir = Path.Combine(baseDir, item.Id);
|
||||
|
||||
if (Directory.Exists(dir))
|
||||
var baseDir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir, cron.ConversationId);
|
||||
if (!Directory.Exists(baseDir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(dir);
|
||||
Thread.Sleep(50);
|
||||
|
||||
var itemFile = Path.Combine(dir, CRONTAB_FILE);
|
||||
var json = JsonSerializer.Serialize(item, _options);
|
||||
File.WriteAllText(itemFile, json);
|
||||
var cronFile = Path.Combine(baseDir, CRON_FILE);
|
||||
var json = JsonSerializer.Serialize(cronFile, _options);
|
||||
File.WriteAllText(cronFile, json);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -47,17 +41,17 @@ public partial class FileRepository
|
|||
}
|
||||
|
||||
var records = new List<CrontabItem>();
|
||||
var dir = Path.Combine(_dbSettings.FileRepository, CRONTAB_FOLDER);
|
||||
var baseDir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir);
|
||||
|
||||
if (!Directory.Exists(dir))
|
||||
if (!Directory.Exists(baseDir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
Directory.CreateDirectory(baseDir);
|
||||
}
|
||||
|
||||
var totalDirs = Directory.GetDirectories(dir);
|
||||
var totalDirs = Directory.GetDirectories(baseDir);
|
||||
foreach (var d in totalDirs)
|
||||
{
|
||||
var file = Path.Combine(d, CRONTAB_FILE);
|
||||
var file = Path.Combine(d, CRON_FILE);
|
||||
if (!File.Exists(file)) continue;
|
||||
|
||||
var json = File.ReadAllText(file);
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ public partial class FileRepository : IBotSharpRepository
|
|||
private const string PLUGIN_CONFIG_FILE = "config.json";
|
||||
private const string STATS_FILE = "stats.json";
|
||||
|
||||
private const string CRONTAB_FOLDER = "crontabs";
|
||||
private const string CRONTAB_FILE = "crontab.json";
|
||||
private const string CRON_FILE = "cron.json";
|
||||
|
||||
public FileRepository(
|
||||
IServiceProvider services,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ public class CrontabItemDocument : MongoBase
|
|||
{
|
||||
return new CrontabItem
|
||||
{
|
||||
Id = item.Id,
|
||||
UserId = item.UserId,
|
||||
AgentId = item.AgentId,
|
||||
ConversationId = item.ConversationId,
|
||||
|
|
@ -37,7 +36,6 @@ public class CrontabItemDocument : MongoBase
|
|||
{
|
||||
return new CrontabItemDocument
|
||||
{
|
||||
Id = item.Id,
|
||||
UserId = item.UserId,
|
||||
AgentId = item.AgentId,
|
||||
ConversationId = item.ConversationId,
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public partial class MongoRepository
|
|||
var filterPromptLog = Builders<LlmCompletionLogDocument>.Filter.In(x => x.ConversationId, conversationIds);
|
||||
var filterContentLog = Builders<ConversationContentLogDocument>.Filter.In(x => x.ConversationId, conversationIds);
|
||||
var filterStateLog = Builders<ConversationStateLogDocument>.Filter.In(x => x.ConversationId, conversationIds);
|
||||
var conbTabItems = Builders<CrontabItemDocument>.Filter.In(x => x.ConversationId, conversationIds);
|
||||
|
||||
var exeLogDeleted = _dc.ExectionLogs.DeleteMany(filterExeLog);
|
||||
var promptLogDeleted = _dc.LlmCompletionLogs.DeleteMany(filterPromptLog);
|
||||
|
|
@ -63,11 +64,13 @@ public partial class MongoRepository
|
|||
var stateLogDeleted = _dc.StateLogs.DeleteMany(filterStateLog);
|
||||
var statesDeleted = _dc.ConversationStates.DeleteMany(filterSates);
|
||||
var dialogDeleted = _dc.ConversationDialogs.DeleteMany(filterDialog);
|
||||
var cronDeleted = _dc.CrontabItems.DeleteMany(conbTabItems);
|
||||
var convDeleted = _dc.Conversations.DeleteMany(filterConv);
|
||||
|
||||
return convDeleted.DeletedCount > 0 || dialogDeleted.DeletedCount > 0 || statesDeleted.DeletedCount > 0
|
||||
|| exeLogDeleted.DeletedCount > 0 || promptLogDeleted.DeletedCount > 0
|
||||
|| contentLogDeleted.DeletedCount > 0 || stateLogDeleted.DeletedCount > 0;
|
||||
|| contentLogDeleted.DeletedCount > 0 || stateLogDeleted.DeletedCount > 0
|
||||
|| convDeleted.DeletedCount > 0;
|
||||
}
|
||||
|
||||
[SideCar]
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ public partial class MongoRepository
|
|||
|
||||
try
|
||||
{
|
||||
item.Id = Guid.NewGuid().ToString();
|
||||
var cronDoc = CrontabItemDocument.ToMongoModel(item);
|
||||
cronDoc.Id = Guid.NewGuid().ToString();
|
||||
_dc.CrontabItems.InsertOne(cronDoc);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue