public Task ExecuteAsync() { _recurringJobManager.AddOrUpdate("check-link", Job.FromExpression <Job1>(m => m.Execute()), Cron.Minutely(), new RecurringJobOptions()); _recurringJobManager.Trigger("check-link"); return(Task.CompletedTask); }
public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env, IRecurringJobManager recurringJobManager) { app.UseHangfireServer(); app.UseHangfireDashboard(""); recurringJobManager.AddOrUpdate("check-link", Job.FromExpression <CheckLinkJob>(m => m.Execute()), Cron.Minutely(), new RecurringJobOptions()); recurringJobManager.Trigger("check-link"); }
public void TriggerJobsByPrefix(string prefixId) { var op = Operation.Begin("Trigger Jobs by Prefix. Prefix: {PrefixId}", prefixId); Log.Information("Loading Hangfire jobs.."); var connection = JobStorage.Current.GetConnection(); var recurringJobs = connection.GetRecurringJobs(); var filteredJobs = recurringJobs.Where(dto => dto.Id.StartsWith(prefixId)).ToList(); Log.Debug( "Found {Count} of {Count1}", filteredJobs.Count, recurringJobs.Count ); var numOfJobs = filteredJobs.Count; Parallel.ForEach( filteredJobs, ( recurringJobDto, parallelLoopState, index ) => { var recurringJobId = recurringJobDto.Id; Log.Debug( "Triggering jobId: {RecurringJobId}, Index: {Index}", recurringJobId, index ); _recurringJobManager.Trigger(recurringJobId); Log.Debug( "Trigger succeeded {RecurringJobId}, Index: {Index}", recurringJobId, index ); } ); Log.Information( "Hangfire jobs successfully trigger. Total: {NumOfJobs}", numOfJobs ); op.Complete(); }
public void AddJobs(IContainer container, IRecurringJobManager recurringJobManager) { Assembly.GetAssembly(typeof(HangfireJobsService)).GetTypes() .Where(x => x.IsAssignableTo <IHangfireJob>() && !x.IsInterface) .Select(x => (x.Name, Job: (IHangfireJob)container.Resolve(x))).ToList() .ForEach(x => { recurringJobManager.AddOrUpdate(this.FixJobName(x.Name), () => x.Job.Do(), this.GetCronExpression(x.Job.Frequency)); if (x.Job.RunOnStart) { recurringJobManager.Trigger(x.Name); } }); }
public void Configure( IApplicationBuilder app, IWebHostEnvironment env, IRecurringJobManager recurringJobs) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints .MapHangfireDashboard("/hangfire", options: new DashboardOptions { Authorization = new[] { new BasicAuthenticationFilter(new[] { new UserCredentials { Username = Configuration["Hangfire:Dashboard:Authentication:Username"], Password = Configuration["Hangfire:Dashboard:Authentication:Password"] } }) } }); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); app.UseHangfireServer(additionalProcesses: new[] { new ProcessMonitor(checkInterval: TimeSpan.FromSeconds(10)) }); recurringJobs.Trigger("SomeJob"); }
public async Task <bool> RunNow(int userjobId) { bool ret = false; if (!await IsAlreadyRunning(userjobId)) { var record = await _dbService.GetBaseData(userjobId); if (record != null) { if (record.HfJobId != null) { if (record.IsRecurringJob()) { _logger.LogInformation("Manually triggering {t} userJobId {i}", record.JobType.ToString(), userjobId); _recClient.Trigger(record.HfJobId); ret = true; } else if (record.IsFireAndForgetOrScheduled()) { _logger.LogInformation("Manually triggering {t} userJobId {i}", record.JobType.ToString(), userjobId); _bgClient.ChangeState(record.HfJobId, new EnqueuedState()); ret = true; } else { throw new Exception($"Cannot manually run userJobId {userjobId}.Invalid JobType Detected."); } } else { _logger.LogWarning("Cannot manually run userJobId {i}. Because HfJobId is null.", userjobId); } } else { _logger.LogWarning("Cannot manually run userJobId {i}. Because user job is not found.", userjobId); } } else { _logger.LogWarning("Cannot manually run userJobId {i}. Because it is already running.", userjobId); } return(ret); }
public async Task <bool> RunAsync(int id) { try { var item = await _dockerCrawlerService.Get <SpiderDto>(x => x.Id == id); if (item != null) { _recurringJobManager.Trigger(item.Name); return(await Task.FromResult(true)); } } catch (Exception e) { _logger.LogException(e, $"启动失败"); } return(await Task.FromResult(false)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IRecurringJobManager recurringJobManager, IServiceProvider serviceProvider) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = ""; }); app.UseAuthentication(); //app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseHangfireDashboard(); // BACKGROUND SERVICE FOR QUOTE OF THE DAY recurringJobManager.AddOrUpdate( "Generate QOTD", () => serviceProvider.GetService <IQuoteOfTheDay>().GenerateRandomQuote(), Cron.Daily ); recurringJobManager.Trigger("Generate QOTD"); }
public void AddServices(IContainer container, IRecurringJobManager recurringJobManager) //TODO maybe rewrite CyclicServices to Jobs would be good idea { var generators = new List <(ICyclicService, RefreshFrequent, bool shouldTriggerNow)> { (container.Resolve <ServerMessagesCacheService>(), RefreshFrequent.Quarterly, false), (container.Resolve <ResponsesCleanupService>(), RefreshFrequent.Daily, false), (container.Resolve <UnmutingService>(), RefreshFrequent.Quarterly, true) // if RefreshFrequent changed remember to change SHORT_MUTE_TIME_IN_MINUTES in unmutingService! }; foreach (var(generator, refreshFrequent, shouldTrigger) in generators) { var cronExpression = this.GetCronExpression(refreshFrequent); recurringJobManager.AddOrUpdate(this.FixJobName(generator.GetType().Name), () => generator.Refresh(), cronExpression); if (shouldTrigger) { recurringJobManager.Trigger(this.FixJobName(generator.GetType().Name)); } } var configurationService = container.Resolve <ConfigurationService>(); recurringJobManager.AddOrUpdate(nameof(ConfigurationService), () => configurationService.Refresh(), this.GetCronExpression(RefreshFrequent.Minutely)); }
public override void ConfigureHangfireJobs(IRecurringJobManager recurringJobManager) { recurringJobManager.AddOrUpdate((string)"check-link", Job.FromExpression <Job1>(m => m.Execute()), Cron.Minutely(), new RecurringJobOptions()); recurringJobManager.Trigger("check-link"); }
public void TriggerJob(string jobId) { recurringJobManager.Trigger(jobId); }
public void Trigger(string id) { _recurringJobManager.Trigger(id); }