-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from RubyOnWorld/jobs-checkout-schedule
jobs-checkout-schedule auto expire user api key
- Loading branch information
Showing
7 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Jobs | ||
class AboutStats < ::Jobs::Scheduled | ||
every 30.minutes | ||
|
||
def execute(args) | ||
About.refresh_stats | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Jobs | ||
class ActivationReminderEmails < ::Jobs::Scheduled | ||
every 2.hours | ||
|
||
def execute(args) | ||
User.joins("LEFT JOIN user_custom_fields ON users.id = user_id AND user_custom_fields.name = 'activation_reminder'") | ||
.where(active: false, staged: false, user_custom_fields: { value: nil }) | ||
.where('users.created_at BETWEEN ? AND ?', 3.days.ago, 2.days.ago) | ||
.find_each do |user| | ||
|
||
user.custom_fields['activation_reminder'] = true | ||
user.save_custom_fields | ||
|
||
email_token = user.email_tokens.create!(email: user.email, scope: EmailToken.scopes[:signup]) | ||
::Jobs.enqueue( | ||
:user_email, | ||
type: "activation_reminder", | ||
user_id: user.id, | ||
email_token: email_token.token | ||
) | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Jobs | ||
|
||
class AutoExpireUserApiKeys < ::Jobs::Scheduled | ||
every 1.day | ||
|
||
def execute(args) | ||
if SiteSetting.expire_user_api_keys_days > 0 | ||
expire_user_api_keys_days = SiteSetting.expire_user_api_keys_days.days.ago | ||
|
||
UserApiKey.where("last_used_at < ?", expire_user_api_keys_days).update_all(revoked_at: Time.zone.now) | ||
end | ||
end | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
# This job will automatically act on records that have gone unhandled on a | ||
# queue for a long time. | ||
module Jobs | ||
class AutoQueueHandler < ::Jobs::Scheduled | ||
|
||
every 1.day | ||
|
||
def execute(args) | ||
return unless SiteSetting.auto_handle_queued_age.to_i > 0 | ||
|
||
Reviewable | ||
.pending | ||
.where('created_at < ?', SiteSetting.auto_handle_queued_age.to_i.days.ago) | ||
.each do |reviewable| | ||
|
||
if reviewable.is_a?(ReviewableFlaggedPost) | ||
reviewable.perform(Discourse.system_user, :ignore, expired: true) | ||
elsif reviewable.is_a?(ReviewableQueuedPost) | ||
reviewable.perform(Discourse.system_user, :reject_post) | ||
elsif reviewable.is_a?(ReviewableUser) | ||
reviewable.perform(Discourse.system_user, :delete_user) | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Jobs | ||
|
||
class BadgeGrant < ::Jobs::Scheduled | ||
def self.run | ||
self.new.execute(nil) | ||
end | ||
|
||
every 1.day | ||
|
||
def execute(args) | ||
return unless SiteSetting.enable_badges | ||
|
||
Badge.enabled.find_each do |b| | ||
begin | ||
BadgeGranter.backfill(b) | ||
rescue => ex | ||
# TODO - expose errors in UI | ||
Discourse.handle_job_exception(ex, error_context({}, code_desc: 'Exception granting badges', extra: { badge_id: b.id })) | ||
end | ||
end | ||
|
||
BadgeGranter.revoke_ungranted_titles! | ||
UserBadge.ensure_consistency! # Badge granter sometimes uses raw SQL, so hooks do not run. Clean up data | ||
UserStat.update_distinct_badge_count | ||
end | ||
|
||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Jobs | ||
|
||
# Runs periodically to send out bookmark reminders, capped at 300 at a time. | ||
# Any leftovers will be caught in the next run, because the reminder_at column | ||
# is set to NULL once a reminder has been sent. | ||
class BookmarkReminderNotifications < ::Jobs::Scheduled | ||
every 5.minutes | ||
|
||
def self.max_reminder_notifications_per_run | ||
@@max_reminder_notifications_per_run ||= 300 | ||
@@max_reminder_notifications_per_run | ||
end | ||
|
||
def self.max_reminder_notifications_per_run=(max) | ||
@@max_reminder_notifications_per_run = max | ||
end | ||
|
||
def execute(args = nil) | ||
bookmarks = Bookmark.pending_reminders.includes(:user).order('reminder_at ASC') | ||
bookmarks.limit(BookmarkReminderNotifications.max_reminder_notifications_per_run).each do |bookmark| | ||
BookmarkReminderNotificationHandler.new(bookmark).send_notification | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Jobs | ||
|
||
class CategoryStats < ::Jobs::Scheduled | ||
every 24.hours | ||
|
||
def execute(args) | ||
Category.update_stats | ||
end | ||
|
||
end | ||
|
||
end |