如何解决在VPS上执行某些命令后,带有托管API的控制台应用只是停止
[Command("synopses",RunMode = RunMode.Async)]
[Summary("Shows current synopses.")]
public async Task Synopses(string username)
{
var warning = await ReplyAsync($"{Context.User.Mention} I am querying the Tracker,this may take a moment.");
var synopses = await _trackerService.GetUserSynopses(username);
var pager = BuildSynopsesPager(synopses);
await warning.DeleteAsync();
await PagedReplyAsync(pager,new ReactionList());
}
_trackerService.GetUserSynopses(username);
是一项非常长的任务,大约需要10秒钟。
public async Task<List<Synopsis>> GetUserSynopses(string username)
{
var synopses = new List<Synopsis>();
// This request to the Google Sheets API is the bulk of the time.
// It gets about 4k rows.
var tracker = await GetTrackerAsync();
foreach (var sheet in tracker.Sheets)
{
var data = sheet.Data;
var writes = data
.Select(x => x.RowData)
.First()
.Where(x => x.Values.Count >= 11)
.Where(x => x.Values[3].FormattedValue == username);
static bool ParseFinal(string text)
{
return text switch
{
"Yes" => true,_ => false
};
}
var result = writes
.Select(write => write.Values)
.Select(cells => new Synopsis
{
DateClaimed = cells[0].FormattedValue,SeriesTitle = cells[1].FormattedValue,SeriesHyperlink = cells[1].Hyperlink ?? "No Hyperlink",ClaimType = Enum.Parse<ClaimType>(cells[2].FormattedValue),Claimant = cells[3].FormattedValue,Document = cells[4].Hyperlink ?? "No Hyperlink",Final = ParseFinal(cells[5].FormattedValue)
});
synopses.AddRange(result);
}
return synopses;
}
public async Task<Spreadsheet> GetTrackerAsync()
{
await using var stream = new FileStream("credentials.json",FileMode.Open,FileAccess.Read);
var credential = GoogleCredential
.FromStream(stream)
.CreateScoped();
var sheetsService = new SheetsService(new BaseClientService.Initializer
{
HttpClientinitializer = credential,ApplicationName = "Hiromi"
});
const string spreadsheetId = "1wbIqigHMGFWZebum8mQjSL5eQzSAXuWZS-8ewbfX4PI";
var request = sheetsService
.Spreadsheets
.Get(spreadsheetId);
request.IncludeGridData = true;
request.Ranges = new[] {"'Synopses In Progress'!A3:K","'Archive'!A2:L"};
return await request.ExecuteAsync();
}
因此,当我的应用程序从IDE在本地运行时运行此命令时,无论执行多少次,它都可以正常工作。但是,当我的应用程序从VPS运行时,它第一次运行,但是第二次执行var warning = await ReplyAsync($"{Context.User.Mention} I am querying the Tracker,this may take a moment.");
,然后挂起一会儿,然后立即停止。
如您所见
[09:41:13 DBG] Foreign key property 'Message.Id' detected as changed. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see property values.
[09:41:13 DBG] A data reader was disposed.
[09:41:13 DBG] Committing transaction.
[09:41:13 DBG] Committing transaction.
[09:41:13 DBG] Closing connection to database 'hiromi' on server 'tcp://149.28.226.90:5432'.
[09:41:13 DBG] Closed connection to database 'hiromi' on server 'tcp://149.28.226.90:5432'.
[09:41:13 DBG] disposing transaction.
[09:41:13 DBG] An 'Message' entity tracked by 'HiromiContext' changed from 'Added' to 'Unchanged'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
[09:41:13 DBG] SaveChanges completed for 'HiromiContext' with 1 entities written to the database.
root@Hamsterland:~/Bots/Hiromi/Hiromi.Bot#
该过程结束了,但不是因为我终止了它;几秒钟后它自动终止。
知道什么问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。