public ActionResult ScheduleRecurringJob(NewRecurringJobBE recurringJobConfig)
        {
            string recurringJobId = recurringJobConfig.JobId.ToLower();;

            // 1st remove the Job if it exists
            RecurringJob.RemoveIfExists(recurringJobId);

            TimeZoneInfo timeZoneInfo = TimeZoneInfo.Local;

            switch (recurringJobConfig.ScheduleTimeZone.ToUpper())
            {
            case "EST":
                timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
                break;

            default:
                timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
                break;
            }

            // run the background job immediately
            //_backgroundJobClient.Enqueue(() => Console.WriteLine("Hello Hangfire job!"));

            // setup a recurring job

            #region Using Expression
            //var manager = new RecurringJobManager();
            //manager.AddOrUpdate(recurringJobId, Job.FromExpression(() => Console.WriteLine("Hello Hangfire job!")), @"0-59 * * * MON,TUE,WED,THU,FRI", timeZoneInfo);
            #endregion

            #region Using Reflection
            //RecurringJob.AddOrUpdate(recurringJobId, () => RequestController.EnqueueRequest(@"EventTypeA",
            //                                                                                @"FIS.Paymetric.POC.EventTypeA.Plugin.EventTypeAPublisher",
            //                                                                                @"FIS.Paymetric.POC.EventTypeA.Plugin",
            //                                                                                @"Execute",
            //                                                                                @"xtobr"),
            //                                                                               @"0-59 * * * MON,TUE,WED,THU,FRI",
            //                                                                               timeZoneInfo);
            #endregion

            //RecurringJob.AddOrUpdate(recurringJobId, () => RequestController.EnqueueRequest(@"EventTypeA"),
            //                                                                   @"0-59 * * * MON,TUE,WED,THU,FRI",
            //                                                                   timeZoneInfo);

            RecurringJob.AddOrUpdate(recurringJobId, () => HangfireManager.EnqueueRequest(recurringJobConfig.JobId,
                                                                                          recurringJobConfig.JobPlugInName,
                                                                                          recurringJobConfig.JobPlugInVersion),
                                     recurringJobConfig.CronSchedule,
                                     timeZoneInfo);

            return(Ok($"Recurring job: [{recurringJobId}] created."));
        }
示例#2
0
        public bool RenewMyAd(int adId)
        {
            var now = DateTime.Now;
            var ad  = CurrentDbContext.ClassifiedDB.Include("Poster").SingleOrDefault(x => x.Id == adId && x.Poster.Id == UserId);

            if (ad == null || ad.ExpiryTimeStamp.Value.Subtract(now).Days > 14)
            {
                return(false);
            }
            ad.ExpiryTimeStamp = ExpiryDate.CalculateDate(DateTime.Now, ad.AdType, ad.Category.Name, ad.SubCategory.Name);
            CurrentDbContext.SaveChanges();
            HangfireManager.ScheduleDateCheck(ad.Id, DateTime.Now, ad.ExpiryTimeStamp.Value);
            return(true);
        }
 private bool SetFeaturedPromotionAd(Trinbago_MVC5.Models.ClassifiedAd ad)
 {
     if (ad.AdPromotion.FeaturedAd != null && !ad.AdPromotion.FeaturedAd.Status && ad.AdPromotion.FeaturedAd.Duration > 0)
     {
         ad.AdPromotion.FeaturedAd.Status = true;
         ad.TimeStamp = DateTime.Now;
         ad.AdPromotion.FeaturedAd.StartDate = DateTime.Now;
         ad.AdPromotion.FeaturedAd.EndDate   = ad.AdPromotion.FeaturedAd.StartDate.Value.AddDays(PromotionStaticInfo.PromotionDuration.DurationRange.SingleOrDefault(x => x.Weeks == ad.AdPromotion.FeaturedAd.Duration).Days);
         ad.ExpiryTimeStamp = ad.TimeStamp.AddMonths(3);
         CurrentDbContext.SaveChanges();
         HangfireManager.ScheduleFeaturedAdExpiry(ad.Id, ad.AdPromotion.FeaturedAd.StartDate.Value, ad.AdPromotion.FeaturedAd.EndDate.Value);
         return(true);
     }
     return(false);
 }
示例#4
0
        public void AdQueueUpdateAd(int adId)
        {
            var ad = CurrentDbContext.ClassifiedDB
                     .Include("Poster")
                     .SingleOrDefault(x => x.Id == adId);

            if (ad != null)
            {
                ad.NeedApproval = false;
                if (ad.Status == 1 || ad.Status == 2)
                {
                    var dtn = DateTime.Now;
                    ad.ExpiryTimeStamp = dtn.AddMonths(1);
                    HangfireManager.ScheduleRemoval(ad.Id, dtn, ad.ExpiryTimeStamp.Value);
                }
                CurrentDbContext.SaveChanges();
                LuceneSearch.ClearLuceneIndexRecord(ad.Id, ad.Photos);
                // Update Lucene
                LuceneSearch.AddUpdateLuceneIndex(ad);
            }
        }
示例#5
0
        public void Configuration(IAppBuilder app)
        {
            var sqlOptions = new SqlServerStorageOptions
            {
                QueuePollInterval          = TimeSpan.FromSeconds(15), // Default value
                PrepareSchemaIfNecessary   = true,                     //default true
                JobExpirationCheckInterval = TimeSpan.FromHours(1),    // 1hr default
                CountersAggregateInterval  = TimeSpan.FromMinutes(5)   // 5 mins default
            };

            // Storage is the only thing required for basic configuration.
            // Just discover what configuration options do you have.
            GlobalConfiguration.Configuration
            .UseSqlServerStorage("DefaultHangfire", sqlOptions)
            //.UseColouredConsoleLogProvider()
            .UseElmahLogProvider();
            //.UseActivator(...)
            //.UseLogProvider(...)

            var backgroundJobServerOptions = new BackgroundJobServerOptions()
            {
                Queues = new[] { "normal", "default" },
                SchedulePollingInterval = new TimeSpan(0, 0, 10),
                ServerCheckInterval     = new TimeSpan(0, 0, 10),
                ServerName = string.Format(
                    "{0}.{1}",
                    Environment.MachineName,
                    Guid.NewGuid())
            };

            app.UseHangfireServer(backgroundJobServerOptions);
            GlobalConfiguration.Configuration.UseFilter(new JobContext());

            var hangfireManager = new HangfireManager();

            hangfireManager.LoadScheduleJob();
        }