当前位置: 首页 > news >正文

做啥英文网站赚钱wordpress支付宝即时到帐

做啥英文网站赚钱,wordpress支付宝即时到帐,做机械设备的做哪个网站推广较好,开发网站需要怎么做作者#xff1a;Julian_酱链接#xff1a;http://www.cnblogs.com/mi12205599/p/10361763.html作为一枚后端程序狗#xff0c;项目实践常遇到定时任务的工作#xff0c;最容易想到的的思路就是利用Windows计划任务/wndows service程序/Crontab程序等主机方法在主机上部署定… 作者Julian_酱链接http://www.cnblogs.com/mi12205599/p/10361763.html作为一枚后端程序狗项目实践常遇到定时任务的工作最容易想到的的思路就是利用Windows计划任务/wndows service程序/Crontab程序等主机方法在主机上部署定时任务程序/脚本。但是很多时候若使用的是共享主机或者受控主机这些主机不允许你私自安装exe程序、Windows服务程序。码甲会想到在web程序中做定时任务 目前有两个方向1、AspNetCore自带的HostService 这是一个轻量级的后台服务 需要搭配timer完成定时任务2、老牌Quartz.Net组件支持复杂灵活的Scheduling、支持ADO/RAM Job任务存储、支持集群、支持监听、支持插件。此处我们的项目使用稍复杂的Quartz.net实现Web定时任务。项目背景最近需要做一个计数程序采用redis计数设定每小时将当日累积数据持久化到关系型数据库sqlite。添加Quartz.Net Nuget 依赖包PackageReference IncludeQuartz Version3.0.6 /1、定义定时任务内容 Job2、设置触发条件 Trigger3、将Quartz.Net集成进AspNet Core头脑风暴IScheduler类包装了上述背景需要完成的第①②点工作 SimpleJobFactory定义了生成指定的Job任务的过程这个行为是利用反射机制调用无参构造函数构造出的Job实例。下面是源码//----------------选自Quartz.Simpl.SimpleJobFactory类-----------using System;using Quartz.Logging;using Quartz.Spi;using Quartz.Util;namespace Quartz.Simpl{    /// summary    /// The default JobFactory used by Quartz - simply calls    /// see crefObjectUtils.InstantiateType{T} / on the job class.    /// /summary    /// seealso crefIJobFactory /    /// seealso crefPropertySettingJobFactory /    /// authorJames House/author    /// authorMarko Lahma (.NET)/author    public class SimpleJobFactory : IJobFactory    {        private static readonly ILog log LogProvider.GetLogger(typeof (SimpleJobFactory));        /// summary        /// Called by the scheduler at the time of the trigger firing, in order to        /// produce a see crefIJob / instance on which to call Execute.        /// /summary        /// remarks        /// It should be extremely rare for this method to throw an exception -        /// basically only the case where there is no way at all to instantiate        /// and prepare the Job for execution.  When the exception is thrown, the        /// Scheduler will move all triggers associated with the Job into the        /// see crefTriggerState.Error / state, which will require human        /// intervention (e.g. an application restart after fixing whatever        /// configuration problem led to the issue with instantiating the Job).        /// /remarks        /// param namebundleThe TriggerFiredBundle from which the see crefIJobDetail /        ///   and other info relating to the trigger firing can be obtained./param        /// param namescheduler/param        /// returnsthe newly instantiated Job/returns        /// throws  SchedulerException if there is a problem instantiating the Job. /throws        public virtual IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)        {            IJobDetail jobDetail bundle.JobDetail;            Type jobType jobDetail.JobType;            try            {                if (log.IsDebugEnabled())                {                    log.Debug($Producing instance of Job {jobDetail.Key}, class{jobType.FullName});                }                return ObjectUtils.InstantiateTypeIJob(jobType);            }            catch (Exception e)            {                SchedulerException se new SchedulerException($Problem instantiating class {jobDetail.JobType.FullName}, e);                throw se;            }        }        /// summary        /// Allows the job factory to destroy/cleanup the job if needed.        /// No-op when using SimpleJobFactory.        /// /summary        public virtual void ReturnJob(IJob job)        {            var disposable job as IDisposable;            disposable?.Dispose();        }    }}//------------------节选自Quartz.Util.ObjectUtils类------------public static T InstantiateTypeT(Type type){     if(type null)     {          throw new ArgumentNullException(nameof(type), Cannot instantiate null);     }     ConstructorInfo ci type.GetConstructor(Type.EmptyTypes);     if (ci null)     {          throw new ArgumentException(Cannot instantiate type which has no empty constructor, type.Name);     }     return (T) ci.Invoke(new object[0]);}很多时候定义的Job任务依赖了其他组件Job实例化时多参此时默认的SimpleJobFactory不能满足实例化要求 需要考虑将Job任务作为依赖注入组件加入依赖注入容器。关键思路① IScheduler 开放了JobFactory 属性便于你控制Job任务的实例化方式JobFactories may be of use to those wishing to have their application produce IJob instances via some special mechanism, such as to give the opportunity for dependency injection②AspNet Core的服务架构是以依赖注入为基础的利用ASPNET Core已有的依赖注入容器IServiceProvider管理Job任务的创建过程。编码实践1、定义Job内容// -------每小时将redis数据持久化到sqlite 每日凌晨跳针持久化昨天全天数据-public class UsageCounterSyncJob : IJob{        private readonly EqidDbContext _context;        private readonly IDatabase _redisDB1;        private readonly ILogger _logger;        public UsageCounterSyncJob(EqidDbContext context, RedisDatabase redisCache, ILoggerFactory loggerFactory)        {            _context context;            _redisDB1 redisCache[1];            _logger loggerFactory.CreateLoggerUsageCounterSyncJob();        }        public async Task Execute(IJobExecutionContext context)        {            // 触发时间在凌晨则同步昨天的计数            var _day DateTime.Now.ToString(yyyyMMdd);            if (context.FireTimeUtc.LocalDateTime.Hour 0)                _day DateTime.Now.AddDays(-1).ToString(yyyyMMdd);            await SyncRedisCounter(_day);            _logger.LogInformation([UsageCounterSyncJob] Schedule job executed.);        }        ...... }2、注册Job和Triggernamespace EqidManager{    using IOCContainer IServiceProvider;    // Quartz.Net启动后注册job和trigger    public class QuartzStartup    {        public IScheduler _scheduler { get; set; }        private readonly ILogger _logger;        private readonly IJobFactory iocJobfactory;        public QuartzStartup(IOCContainer IocContainer, ILoggerFactory loggerFactory)        {            _logger loggerFactory.CreateLoggerQuartzStartup();            iocJobfactory new IOCJobFactory(IocContainer);            var schedulerFactory new StdSchedulerFactory();            _scheduler schedulerFactory.GetScheduler().Result;            _scheduler.JobFactory iocJobfactory;        }        public void Start()        {            _logger.LogInformation(Schedule job load as application start.);            _scheduler.Start().Wait();            var UsageCounterSyncJob JobBuilder.CreateUsageCounterSyncJob()               .WithIdentity(UsageCounterSyncJob)               .Build();            var UsageCounterSyncJobTrigger TriggerBuilder.Create()                .WithIdentity(UsageCounterSyncCron)                .StartNow()                // 每隔一小时同步一次                .WithCronSchedule(0 0 * * * ?)      // Seconds,Minutes,HoursDay-of-MonthMonthDay-of-WeekYearoptional field                .Build();            _scheduler.ScheduleJob(UsageCounterSyncJob, UsageCounterSyncJobTrigger).Wait();            _scheduler.TriggerJob(new JobKey(UsageCounterSyncJob));        }        public void Stop()        {            if (_scheduler null)            {                return;            }            if (_scheduler.Shutdown(waitForJobsToComplete: true).Wait(30000))                _scheduler null;            else            {            }            _logger.LogCritical(Schedule job upload as application stopped);        }    }    /// summary    /// IOCJobFactory 实现在Timer触发的时候注入生成对应的Job组件    /// /summary    public class IOCJobFactory : IJobFactory    {        protected readonly IOCContainer Container;        public IOCJobFactory(IOCContainer container)        {            Container container;        }        //Called by the scheduler at the time of the trigger firing, in order to produce        //a Quartz.IJob instance on which to call Execute.        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)        {            return Container.GetService(bundle.JobDetail.JobType) as IJob;        }        // Allows the job factory to destroy/cleanup the job if needed.        public void ReturnJob(IJob job)        {        }    }}3、结合ASpNet Core 注入组件绑定Quartz.Net//-------------------------------截取自Startup文件---------------......services.AddTransientUsageCounterSyncJob();     // 这里使用瞬时依赖注入services.AddSingletonQuartzStartup();......// 绑定Quartz.Netpublic void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IApplicationLifetime lifetime, ILoggerFactory loggerFactory){     var quartz app.ApplicationServices.GetRequiredServiceQuartzStartup();     lifetime.ApplicationStarted.Register(quartz.Start);     lifetime.ApplicationStopped.Register(quartz.Stop);}附IIS 网站低频访问导致工作进程进入闲置状态的 解决办法IIS为网站默认设定了20min闲置超时时间20分钟内没有处理请求、也没有收到新的请求工作进程就进入闲置状态。IIS上低频web访问会造成工作进程关闭此时应用程序池回收Timer等线程资源会被销毁当工作进程重新运作Timer可能会重新生成起效 但我们的设定的定时Job可能没有按需正确执行。故为在IIS网站实现低频web访问下的定时任务设置Idle TimeOut 0同时将【应用程序池】-【正在回收】-不勾选【回收条件】
http://www.zqtcl.cn/news/366893/

相关文章:

  • 柳州公司网站制作公司wordpress 网店
  • 网站增加栏目费用在网站开发中如何设置登录
  • 怎样用php做网站百度推广联系人
  • 怎么建立手机网站如何申请公司域名
  • 营销型网站怎么收费邓州企业网站
  • 北京建设官方网站邢台网站维护
  • 新余网站制作网站开发工资咋样
  • 襄阳网站建设外包自己做一个网站
  • 网站域名的后缀wordpress文章归类
  • 查询企业信息的官方网站大连建设网站公司
  • 网站建设 全包专业建设规划方案模板
  • 做网站好还是做微信小程序好浙江建设工程造价信息网站
  • 网站开发怎么报价推广普通话手抄报模板可打印
  • 好的平面网站模板企业网站建设浩森宇特
  • 做网站通过什么赚钱吗公司建设网站的费用
  • 如何做建筑一体化的网站视频网站开发应用到哪些技术
  • 巴中微信网站建设竞价托管一般多少钱
  • 彩票网站开发 违法股票网站排名哪个好
  • 宝格丽网站建设哈尔滨网站建设王道下拉強
  • 烟台网站建设的公司世界500强企业排名2021
  • 网络营销做得比较成功的案例吴中seo网站优化软件
  • 怎么设立网站美区下载的app怎么更新
  • 建立网站ppt做酒店网站所用到的算法
  • 上海网站建设的价格低太仓做网站的公司
  • 怎样登录建设互联网站怎么做中英文网站
  • 云网站7china中小企业网站建设好么
  • 美丽南方官网网站建设国际新闻最新消息今天摘抄
  • 牛商网营销型网站多少钱江门营销型网站建设多少钱
  • 小榄公司网站建设网站交互做的比较好的
  • 深圳定制网站建设怎么改版网站