Created
September 6, 2011 10:03
-
-
Save moniyax/1197172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment