Skip to content

Commit fd75709

Browse files
committed
Merge pull request coderwall#190 from just3ws/master
Restoring previously scheduled tasks.
2 parents 0810d36 + 5bcfdfe commit fd75709

27 files changed

+174
-534
lines changed

app/clock.rb

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,44 @@
55

66
include Clockwork
77

8+
# On the first of every month send the popular protips from the previous month.
9+
every(1.day, 'protip_mailer:popular_protips', if: ->(t){ t.day == 1 }) do
10+
if ENV['PROTIP_MAILER_POPULAR_PROTIPS']
11+
last_month = 1.month.ago
12+
ProtipMailerPopularProtipsWorker.perform_async(last_month.beginning_of_month, last_month.end_of_month)
13+
else
14+
Rails.logger.warn('PROTIP_MAILER_POPULAR_PROTIPS is disabled. Set `heroku config:set PROTIP_MAILER_POPULAR_PROTIPS=true` to allow sending scheduled emails.')
15+
end
16+
end
817

9-
# Runs as 1:01 AM Pacific
10-
every(1.day, 'award:activate:active', at: '01:01') do
11-
ActivatePendingUsersWorker.perform_async
18+
every(1.day, 'teams:refresh', at: '22:00') do
19+
TeamsRefreshJob.perform_async
1220
end
1321

1422
every(1.day, 'award:refresh:stale', at: '00:00') do
1523
RefreshStaleUsersWorker.perform_async
1624
end
1725

18-
# On the first of every month send the popular protips from the previous month.
19-
every(1.day, 'protip_mailer:popular_protips', if: ->(t){ t.day == 1 }) do
20-
last_month = 1.month.ago
21-
ProtipMailerPopularProtipsWorker.perform_async(last_month.beginning_of_month, last_month.end_of_month)
26+
# Runs as 1:00 AM Pacific
27+
every(1.day, 'award:activate:active', at: '01:00') do
28+
ActivatePendingUsersWorker.perform_async
29+
end
30+
31+
every(1.day, 'cleanup:protips:associate_zombie_upvotes', at: '02:00') do
32+
CleanupProtipsAssociateZombieUpvotesJob.perform_async
33+
end
34+
35+
every(1.day, 'search:sync', at: '03:00') do
36+
SearchSyncJob.perform_async
37+
end
38+
39+
every(1.day, 'protips:recalculate_scores', at: '04:00') do
40+
ProtipsRecalculateScoresJob.perform_async
41+
end
42+
43+
every(1.day, 'clear_expired_sessions', at: '05:00') do
44+
ClearExpiredSessionsJob.perform_async
2245
end
2346

24-
every(1.day, 'cleanup:protips:associate_zombie_upvotes', at: '00:00') {}
25-
every(1.day, 'clear_expired_sessions', at: '00:00') {}
26-
every(1.day, 'facts:system', at: '00:00') {}
27-
every(1.day, 'protips:recalculate_scores', at: '00:00') {}
28-
every(1.day, 'search:sync', at: '00:00') {}
29-
every(1.day, 'teams:refresh', at: '00:00') {}
47+
# This is tied with broken code. Probably should delete
48+
# every(1.day, 'facts:system', at: '00:00') {}

app/jobs/award_user_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class AwardUserJob
44
sidekiq_options queue: :low
55

66
def perform(username, badges)
7-
user = User.find_by_username(username)
7+
user = User.with_username(username)
88

99
if badges.first.is_a?(String)
1010
badges.map!(&:constantize)
@@ -13,4 +13,4 @@ def perform(username, badges)
1313
user.check_achievements!(badges)
1414
end
1515

16-
end
16+
end

app/jobs/build_activity_stream_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class BuildActivityStreamJob
44
sidekiq_options queue: :medium
55

66
def perform(username)
7-
user = User.find_by_username(username)
7+
user = User.with_username(username)
88
user.build_repo_followed_activity!
99
end
10-
end
10+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CleanupProtipsAssociateZombieUpvotesJob
2+
include Sidekiq::Worker
3+
4+
sidekiq_options queue: :low
5+
6+
def perform
7+
Like.joins('inner join users on users.tracking_code = likes.tracking_code').
8+
where('likes.tracking_code is not null').
9+
where(user_id: nil).
10+
find_each(batch_size: 100) do |like|
11+
ProcessLikeJob.perform_async(:associate_to_user, like.id)
12+
end
13+
end
14+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class ClearExpiredSessionsJob
2+
include Sidekiq::Worker
3+
4+
sidekiq_options queue: :low
5+
6+
def perform
7+
ActiveRecord::SessionStore::Session.delete_all(["updated_at < ?", 7.days.ago])
8+
end
9+
end

app/jobs/deactivate_team_jobs_job.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ def perform(id)
99
job.deactivate!
1010
end
1111
end
12-
1312
end

app/jobs/generate_top_users_composite_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# TODO: Broken, generates errors due to changes in `convert` (ImageMagick)
2+
13
class GenerateTopUsersCompositeJob
24
include Sidekiq::Worker
35

app/jobs/github_badge_org_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class GithubBadgeOrgJob
44
sidekiq_options queue: :medium
55

66
def perform(username, action)
7-
user = User.find_by_username(username)
7+
user = User.with_username(username)
88
unless user.nil? or user.github.nil?
99
if action.to_sym == :add
1010
GithubBadge.new.add_all(user.badges, user.github)
@@ -13,4 +13,4 @@ def perform(username, action)
1313
end
1414
end
1515
end
16-
end
16+
end

app/jobs/process_like_job.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ def perform(process_type, like_id)
99
when 'associate_to_user'
1010
begin
1111
like.user_id = User.find_by_tracking_code(like.tracking_code)
12-
like.save
13-
rescue ActiveRecord::RecordNotUnique
12+
like.save!
13+
rescue ActiveRecord::RecordNotUnique => ex
14+
ap ex
1415
like.destroy
1516
end
1617
end
1718
end
18-
end
19+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class ProtipsRecalculateScoresJob
2+
include Sidekiq::Worker
3+
4+
sidekiq_options queue: :low
5+
6+
def perform
7+
Protip.where('created_at > ?', 25.hours.ago).where(upvotes_value_cache: nil).each do |protip|
8+
ProcessProtipJob.perform_async(:recalculate_score, protip.id)
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)