Esempio n. 1
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();
        }
Esempio n. 2
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);
        }
        public async Task Create_WellFormedUrl_AccessMongoLazily()
        {
            const string stubMongoUrl = "mongodb://fake-url:27017/fake_database_name/?serverSelectionTimeoutMs=100";

            var mongoRepository = MongoRepositoryFactory.Create(stubMongoUrl);

            await Assert.ThrowsAsync <TimeoutException>(() => mongoRepository.GetJobStatistic());
        }
Esempio n. 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddHorariumServer(MongoRepositoryFactory.Create("mongodb://localhost:27017/horarium"));

            services.AddSingleton(_ => new MongoContext("mongodb://localhost:27017/peka_db"));

            services.AddSingleton <IPekaRepository, PekaRepository>();
            services.AddSingleton <ICockroachPekaRepository, CockroachPekaRepository>();
            services.AddSingleton <ICounterRepository, CounterRepository>();

            services.AddSingleton <IFcmSender, FcmSender>();
            services.AddSingleton <DailyPekaJob>();
        }
Esempio n. 5
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);
        }
        public void Create_NullMongoUrl_Exception()
        {
            MongoUrl mongoUrl = null;

            Assert.Throws <ArgumentNullException>(() => MongoRepositoryFactory.Create(mongoUrl));
        }
        public void Create_NullConnectionString_Exception()
        {
            string connectionString = null;

            Assert.Throws <ArgumentNullException>(() => MongoRepositoryFactory.Create(connectionString));
        }