示例#1
0
        public void ScheduleJobOnlyOnce <T>(string uniqueName, T jobInfo, DateTime schedule, Recurrence r = null,
                                            string jobRoute = null) where T : class
        {
            Debug.Assert(null != jobInfo);

            bool exists;

            using (var ds = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute))
            {
                exists = ds.Query <ScheduledItem>().Any(i => i.UniqueName == uniqueName);
            }

            if (!exists)
            {
                var log = ClassLogger.Create(typeof(JobDocumentsScheduler));


                log.InfoFormat("Scheduling job: {0} at time {1}, recurring: {2}, route = {3}", jobInfo, schedule,
                               r == null ? string.Empty : r.ToString(), jobRoute);

                using (var ds = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute))
                {
                    ds.Store(new ScheduledItem(uniqueName, JsonConvert.SerializeObject(jobInfo, _settings),
                                               typeof(T), jobRoute, schedule, r));
                    ds.SaveChanges();
                }
            }
        }