简体   繁体   中英

Schedule badge update task process in asp.net mvc

I have found code on implementing batch update for awarding badges as follow. However, i have no idea on how to implement this in asp.net MVC. From what i have known, the implementation should be done in global.asax file in MVC. How should i trigger this in global.asax file?

 public abstract class BadgeJob { protected BadgeJob() { //start cycling on initialization Insert(); } //override to provide specific badge logic protected abstract void AwardBadges(); //how long to wait between iterations protected abstract TimeSpan Interval { get; } private void Callback(string key, object value, CacheItemRemovedReason reason) { if (reason == CacheItemRemovedReason.Expired) { this.AwardBadges(); this.Insert(); } } private void Insert() { HttpRuntime.Cache.Add(this.GetType().ToString(), this, null, Cache.NoAbsoluteExpiration, this.Interval, CacheItemPriority.Normal, this.Callback); } } public class CommenterBadge : BadgeJob { public CommenterBadge() : base() { } protected override void AwardBadges() { //select all users who have more than x comments //and dont have the commenter badge //add badges } //run every 10 minutes protected override TimeSpan Interval { get { return new TimeSpan(0,10,0); } } } 

IMHO and experience, it is not possible and advisable to do a batch job ora task from the web context. It is always recommended to do a entry in the db from the web context.the next step will be to have a windows service to take the data and process you can also refer to the Quartz.net for this task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM