private void InitializedData(PortalDbContext context) { if (!context.DockerRepositories.Any()) { context.DockerRepositories.Add(new DockerRepository { Name = "default", Schema = "http", Registry = "registry.zousong.com:5000", Repository = "dotnetspider.spiders", CreationTime = DateTime.Now, UserName = "", Password = "" }); context.SaveChanges(); } }
private void InitializedData(PortalDbContext context, IScheduler sched) { if (!context.DockerRepositories.Any()) { var repo = new DockerRepository { Name = "DockerHub", Schema = null, Registry = null, Repository = "dotnetspider/spiders.startup", CreationTime = DateTimeOffset.Now, UserName = "", Password = "" }; context.DockerRepositories.Add(repo); var spider = new Entity.Spider { Name = "cnblogs", Cron = "0 1 */1 * * ?", Repository = "dotnetspider/spiders.startup", Type = "DotnetSpider.Spiders.CnblogsSpider", Tag = "latest", CreationTime = DateTimeOffset.Now }; context.Spiders.Add(spider); context.SaveChanges(); var trigger = TriggerBuilder.Create().WithCronSchedule(spider.Cron).WithIdentity(spider.Id.ToString()) .Build(); var qzJob = JobBuilder.Create <TriggerJob>().WithIdentity(spider.Id.ToString()) .WithDescription(spider.Name) .RequestRecovery(true).Build(); sched.ScheduleJob(qzJob, trigger).GetAwaiter().GetResult(); } }