Example #1
0
        private static async Task InitializeSeedDataAsync(PortalDbContext context, IScheduler sched)
        {
            if (!await context.Spiders.AnyAsync())
            {
                var spider = new Data.Spider
                {
                    Name                 = "cnblogs",
                    Cron                 = "0 1 */1 * * ?",
                    Type                 = "DotnetSpider.Spiders.CnblogsSpider",
                    Image                = "dotnetspider/spiders.startup:latest",
                    CreationTime         = DateTimeOffset.Now,
                    Enabled              = true,
                    LastModificationTime = DateTimeOffset.Now
                };
                await context.Spiders.AddAsync(spider);

                await context.SaveChangesAsync();

                var trigger = TriggerBuilder.Create().WithCronSchedule(spider.Cron)
                              .WithIdentity(spider.Id.ToString())
                              .Build();
                var qzJob = JobBuilder.Create <QuartzJob>().WithIdentity(spider.Id.ToString())
                            .WithDescription(spider.Name)
                            .RequestRecovery(true).Build();
                await sched.ScheduleJob(qzJob, trigger);
            }
        }
Example #2
0
        private static async Task InitializeSeedDataAsync(PortalDbContext context, IScheduler sched)
        {
            if (!await context.DockerRepositories.AnyAsync())
            {
                var repo = new DockerRepository
                {
                    Name         = "DockerHub",
                    Schema       = null,
                    Registry     = null,
                    Repository   = "dotnetspider/spiders.startup",
                    CreationTime = DateTimeOffset.Now,
                    UserName     = "",
                    Password     = ""
                };
                await context.DockerRepositories.AddAsync(repo);

                var spider = new Data.Spider
                {
                    Name         = "cnblogs",
                    Cron         = "0 1 */1 * * ?",
                    Repository   = "dotnetspider/spiders.startup",
                    Type         = "DotnetSpider.Spiders.CnblogsSpider",
                    Tag          = "latest",
                    CreationTime = DateTimeOffset.Now
                };
                await context.Spiders.AddAsync(spider);

                await context.SaveChangesAsync();

                var trigger = TriggerBuilder.Create().WithCronSchedule(spider.Cron)
                              .WithIdentity(spider.Id.ToString())
                              .Build();
                var qzJob = JobBuilder.Create <QuartzJob>().WithIdentity(spider.Id.ToString())
                            .WithDescription(spider.Name)
                            .RequestRecovery(true).Build();
                await sched.ScheduleJob(qzJob, trigger);
            }
        }