hangfire

120行代码打造.netcore生产力工具-小而美的后台异步组件

怎甘沉沦 提交于 2020-08-05 08:28:01
相信绝大部分开发者都接触过用户注册的流程,通常情况下大概的流程如下所示: 接收用户提交注册信息 持久化注册信息(数据库+redis) 发送注册成功短信(邮件) 写操作日志(可选) 伪代码如下: public async Task<IActionResult> Reg([FromBody] User user) { _logger.LogInformation("持久化数据开始"); await Task.Delay(50); _logger.LogInformation("持久化结束"); _logger.LogInformation("发送短信开始"); await Task.Delay(100); _logger.LogInformation("发送短信结束"); _logger.LogInformation("操作日志开始"); await _logRepository.Insert(new Log { Txt = "注册日志" }); _logger.LogInformation("操作日志结束"); return Ok("注册成功"); } 在以上的代码中,我使用Task.Delay方法阻塞主线程,用以模拟实际场景中的执行耗时。以上流程应该是包含了绝大部分注册流程所需要的操作。对于任何开发者来讲,以上业务流程没任何难度,无非是顺序的执行各个流程的代码即可。

基于 abp vNext 和 .NET Core 开发博客项目

北慕城南 提交于 2020-08-04 20:25:16
系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 基于 abp vNext 和 .NET Core 开发博客项目 - 完善与美化,Swagger登场 基于 abp vNext 和 .NET Core 开发博客项目 - 数据访问和代码优先 基于 abp vNext 和 .NET Core 开发博客项目 - 自定义仓储之增删改查 基于 abp vNext 和 .NET Core 开发博客项目 - 统一规范API,包装返回模型 基于 abp vNext 和 .NET Core 开发博客项目 - 再说Swagger,分组、描述、小绿锁 基于 abp vNext 和 .NET Core 开发博客项目 - 接入GitHub,用JWT保护你的API 基于 abp vNext 和 .NET Core 开发博客项目 - 异常处理和日志记录 基于 abp vNext 和 .NET Core 开发博客项目 - 使用Redis缓存数据 基于 abp vNext 和 .NET Core 开发博客项目 - 集成Hangfire实现定时任务处理 基于 abp vNext 和 .NET Core 开发博客项目 - 用AutoMapper搞定对象映射 基于 abp

Add HttpContext into HangFire

耗尽温柔 提交于 2020-08-04 06:03:21
问题 I am a beginner with HangFire and looking forward to using HangFire to call some actions in my web application monthly. But these actions require HttpContext. Then my question is: Is there any way to add (or create) a httpcontext in HangFire project? I tried to google but no suitable answer. Thanks for your help! I found a short discussion. Sad to see the answer is "no way". Update: Ref https://discuss.hangfire.io/t/passing-site-url-to-hangfire-recurrent-jobs/2641 回答1: I have a similar

What is the difference between the nuget packages hangfire.aspnetcore and hangfire and hangfire.core?

血红的双手。 提交于 2020-07-08 10:59:28
问题 What is the difference between the nuget packages HangFire.AspNetCore and HangFire and HangFire.core? It seems I am able to use hangfire with a ASP .NET MVC Core project with only the HangFire 1.6.21 package alone. See below packages used in my project: What is then the package HangFire.AspNetCore for? I am working with Visual Studio Code on Ubuntu, and I added the packages using : dotnet add package Hangfire dotnet add package Hangfire.AspNetCore 回答1: It's the usual naming convention for

Hangfire keeps running SQL queries even when inactive

泄露秘密 提交于 2020-06-11 20:12:57
问题 I'm developing an ASP.net MVC 5 web site and I'm using Hangfire for scheduling some tasks, in this case just one every 3 min. I know for a fact that it takes only a few seconds to run such task (and the DB query associated with it). The problem I'm facing is that it seems as if Hangfire has my SQL Server running "something" (I don't know what) and I can see in the SQL Server Activity Monitor that my CPU stays always at 20+% usage and there are Database I/O operations at (1.2 MB/sec average).

Hangfire keeps running SQL queries even when inactive

房东的猫 提交于 2020-06-11 20:07:23
问题 I'm developing an ASP.net MVC 5 web site and I'm using Hangfire for scheduling some tasks, in this case just one every 3 min. I know for a fact that it takes only a few seconds to run such task (and the DB query associated with it). The problem I'm facing is that it seems as if Hangfire has my SQL Server running "something" (I don't know what) and I can see in the SQL Server Activity Monitor that my CPU stays always at 20+% usage and there are Database I/O operations at (1.2 MB/sec average).

Hangfire in ASP.Net Core : simple recurring job does not refresh its dynamic content

∥☆過路亽.° 提交于 2020-06-09 02:55:53
问题 I am trying to implement cron task on a web application in ASP.Net Core 1.1. I decided to choose the Hangfire library. In order to check if my installation and configuration were working fine, I just wrote a very simple recurring job, aimed to print the current DateTime on the console output : RecurringJob.AddOrUpdate(() => Console.WriteLine($"{DateTime.Now}"), Cron.Minutely); The weird thing is that every minute, it prints the same message , corresponding to the date and time of the first

Exposing hangfire without auth

三世轮回 提交于 2020-05-29 10:47:24
问题 Is there a way to expose Hangfire in IIS without having to configure authorization? In this specific case the dashboard should be open, but when accessing it (not in debug) it returns a 401 code. 回答1: I think you should be able to write a custom implementation of IDashboardAuthorizationFilter as described in the documentation. Be aware that the default is only local requests to the dashboard are allowed. It's also recommended that you really use authorization and do not publish unauthorized

.Net Core 商城微服务项目系列(十五): 构建定时任务调度和消息队列管理系统

放肆的年华 提交于 2020-04-28 05:54:12
一.系统描述 嗨,好久不见各位老哥,最近有点懒,技术博客写的太少了,因为最近在写小说,写的顺利的话说不定就转行了,哈哈哈哈哈哈哈哈哈。 今天要介绍的是基于.Net Core的定时任务调度和消息队列管理系统。相信大家对这两个肯定都已经很熟悉了,在开发过程中,这两个组件扮演了不可或缺的角色: 消息队列帮助我们进行 ”解耦“、”异步“、”削峰“ 定时任务帮助我们进行 "后台"、”监控"、“补偿" 定时任务调度系统大家都介绍过很多次了,园子里的很多文章我也都拜读过,我相信大家实际的工作中肯定也都在频繁的使用它。目前主流的组件有 Quartz和Hangfire两种,在两者的选择上来说建议大家熟悉哪个用哪个就可以,Hangfire是自带UI管理界面的,所以如果想直接接入系统并且不想再进行二次开发做UI,可以直接选择Hangfire。 因为我对于Quartz更熟悉,所以本系统的定时任务调度基于Quartz开发,消息队列基于RabbitMQ,同时有一套UI,用于可视化操作定时任务调度和管理消息队列配置。 本系统是开发自用的,原型是公司工作中使用的系统,私下里重写了一套后台代码,但是UI还是公司的那一套,因为是自用,所以无法达到直接开箱即用的效果,写这篇的目的只是希望分享两者的使用方式和场景,帮助各位在遇到相同应用场景的问题时能够有更多解决思路。 二.功能介绍 1.MQ界面化动态配置

How can I publish Hangfire Dashboard for a custom web page?

陌路散爱 提交于 2020-04-18 12:35:40
问题 I know that Hangfire set their dashboard to local only for security purposes. Then if I want to open it in a custom domain, I have to set the authorization for it. I have followed the Configuring Authorization guide but I don't understand what do I have to write inside app.UseCookieAuthentication(…) . app.UseCookieAuthentication(new CookieAuthenticationOptions() { }); It returns me an error of Can't find namespace for CookieAuthenticationOptions This code might be deprecated and does not work