我想创建一个基于事件的通知和徽章系统,当用户完成某些目标时,该系统会奖励用户。目标可能包括:
- 在论坛上发布 20 个条目 ->主页上提醒突出显示用户,授予徽章
- 连续 10 天登录网站 ->恭喜在主页上向用户留言
- 评论了 10 个论坛帖子 ->论坛徽章奖
这是 AASM 这样的国家机器的工作吗?我没怎么玩过这样的系统。这是定义事件的方法还是有更好的插件/解决方案可以适应这种类型的行为?任何教程或方法建议将不胜感激。
I want to create an event-based notification and badging system that would award users when they accomplish certain goals. Goals might include:
- Posting 20 entries on a forum -> alert on homepage highlighting user, award of badge
- Logging in to the site 10 days straight -> congrats to message to user on homepage
- Commenting on 10 forum posts -> forum badge award
Would this be a job for a state machine such as AASM? I haven't played much with such systems. Would that be the way to go to define events or are there better plugins/solutions that would accommodate this type of behavior? Any tutorials or recommendations for approach would be greatly appreciated.
发布评论
评论(1)
看来这里棘手的部分是弄清楚您希望如何维持确定何时授予徽章所需的状态。 Rails 的状态机插件在这方面对你没有多大帮助。
例如,一段代码如何确定用户是否已连续登录 10 天?一旦你弄清楚了这一点,你就可以担心如何组织事件处理。
当他们获得徽章时,您是否需要实时通知他们?如果是这样,那么您可以使用 ActiveRecord::Observer 轻松完成此操作,但从长远来看,它可能会出现一些延迟问题(http://api.rubyonrails.org/classes/ActiveRecord/Observer.html)
如果您不需要实时执行此操作,那么您可以使用某种形式的后台作业来执行此操作。有很多用于后台工作的库。当我不关心扩展而只想快速完成某些事情时,我会使用工作。
It seems that the tricky part here is figuring out how you want to maintain the state needed to determine when a badge should be awarded. The state machine plugins for rails aren't going to help you much with that.
For example, how would a piece of code determine if a user has logged in 10 days straight? Once you figure this out then you can worry about how to organize the event handling.
Do you need to notify them in real time when they get a badge? If so they then you can easily do this with ActiveRecord::Observer but it may have some latency issues in thelong run (http://api.rubyonrails.org/classes/ActiveRecord/Observer.html)
If you don't need to do it in real time then you can do it with background jobs of some form. There are a lot of libraries for background jobs out there. I use workling when I don't care about scaling and just want to get something up fast.