feat: 新增评选项目的定时任务

This commit is contained in:
lexiaozhang 2023-10-05 23:41:16 +08:00
parent ec0a6be9d4
commit 9f3375806f
5 changed files with 23 additions and 28 deletions

View File

@ -1,33 +1,6 @@
class Admins::ProjectEvaluationController < Admins::BaseController
def update
Project.where(is_public: 1, id: Repository.pluck(:project_id)).find_each do |project|
ProjectEvaluation.update_raw_scores(project)
end
ProjectEvaluation.update_normalized_scores
def evaluate_and_update(interval)
ProjectEvaluationTop.top_projects_selection(interval)
ProjectEvaluation.update_scores_by_interval(interval)
end
current_date = Date.today
if current_date.wday == 1
evaluate_and_update(:weekly)
end
if current_date.day == 1
evaluate_and_update(:monthly)
end
if current_date.day == 1 && [1, 4, 7, 10].include?(current_date.month)
evaluate_and_update(:quarterly)
end
if current_date.yday == 1
evaluate_and_update(:yearly)
end
ProjectEvaluation.update_all
render_ok()
end
end

View File

@ -0,0 +1,7 @@
class EvaluateProjectJob < ApplicationJob
queue_as :message
def perform(*args)
ProjectEvaluation.update_all
end
end

View File

@ -54,4 +54,9 @@ class ProjectEvaluationTop < ApplicationRecord
)
end
end
def self.evaluate_and_update(interval)
ProjectEvaluationTop.top_projects_selection(interval)
ProjectEvaluation.update_scores_by_interval(interval)
end
end

View File

@ -7,3 +7,8 @@ delay_expired_issue:
cron: "0 0 * * *"
class: "DelayExpiredIssueJob"
queue: message
evaluate_project:
cron: "0 0 * * *"
class: "EvaluateProjectJob"
queue: message

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe EvaluateProjectJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
end