* Use timezone aware datetime methods * Use timezone aware date parse for GitHub issue tag * Introduce a bit of chaos programming using Zonebie Zonebie uses a random timezone to run tests, it's a really good way to see if the code is timezone dependent or not. * Convert GitHub issue date as UTC
19 lines
602 B
Ruby
19 lines
602 B
Ruby
class ModerationService
|
|
def initialize
|
|
@available_moderators = User.with_role(:trusted).where("last_moderation_notification < ?", 28.hours.ago)
|
|
end
|
|
|
|
def send_moderation_notification(object)
|
|
if @available_moderators.any?
|
|
moderator = @available_moderators.sample
|
|
Notification.create(
|
|
user_id: moderator.id,
|
|
notifiable_id: object.id,
|
|
notifiable_type: object.class.name,
|
|
action: "Moderation",
|
|
)
|
|
moderator.update_column(:last_moderation_notification, Time.current)
|
|
end
|
|
end
|
|
handle_asynchronously :send_moderation_notification
|
|
end
|