Exemple #1
0
        protected HorariumServer CreateHorariumServer()
        {
            var dataBase = Environment.GetEnvironmentVariable("DataBase");

            IJobRepository jobRepository;

            switch (dataBase)
            {
            case "MongoDB":
                jobRepository = MongoRepositoryFactory.Create(ConnectionMongo);
                break;

            case "Memory":
                jobRepository = new InMemoryRepository();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dataBase), dataBase, null);
            }

            var horarium = new HorariumServer(jobRepository);

            horarium.Start();

            return(horarium);
        }
Exemple #2
0
        static async Task StartScheduler()
        {
            var horarium =
                new HorariumServer(MongoRepositoryFactory.Create("mongodb://localhost:27017/schedOpenSource"));

            await horarium.CreateRecurrent <TestRecurrentJob>(Cron.SecondInterval(10)).Schedule();

            await new HorariumClient(MongoRepositoryFactory.Create("mongodb://localhost:27017/schedOpenSource"))
            .GetJobStatistic();

            var firstJobDelay = TimeSpan.FromSeconds(20);

            var secondJobDelay = TimeSpan.FromSeconds(15);

            await horarium
            .Create <TestJob, int>(1)  // 1-st job
            .WithDelay(firstJobDelay)
            .Next <TestJob, int>(2)    // 2-nd job
            .WithDelay(secondJobDelay)
            .Next <TestJob, int>(3)    // 3-rd job (global obsolete from settings and no delay will be applied)
            .Schedule();

            await horarium.Create <TestJob, int>(666)
            .WithDelay(TimeSpan.FromSeconds(25))
            .Schedule();

            await Task.Delay(20000);

            await horarium.CreateRecurrent <TestRecurrentJob>(Cron.SecondInterval(15))
            .WithKey(nameof(TestRecurrentJob))
            .Schedule();
        }
Exemple #3
0
        private IHorarium CreateScheduler(DataBase dataBase)
        {
            IJobRepository jobRepository;

            switch (dataBase)
            {
            case DataBase.MongoDB:
                jobRepository = MongoRepositoryFactory.Create(ConnectionMongo);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dataBase), dataBase, null);
            }

            var horarium = new HorariumServer(jobRepository);

            horarium.Start();

            return(horarium);
        }
Exemple #4
0
 public HorariumServerHostedService(IHorarium horarium)
 {
     _horariumServer = (HorariumServer)horarium;
 }