forked from Trustie/forgeplus
feat: 新增评选项目的定时任务
This commit is contained in:
parent
ec0a6be9d4
commit
9f3375806f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
class EvaluateProjectJob < ApplicationJob
|
||||
queue_as :message
|
||||
|
||||
def perform(*args)
|
||||
ProjectEvaluation.update_all
|
||||
end
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -7,3 +7,8 @@ delay_expired_issue:
|
|||
cron: "0 0 * * *"
|
||||
class: "DelayExpiredIssueJob"
|
||||
queue: message
|
||||
|
||||
evaluate_project:
|
||||
cron: "0 0 * * *"
|
||||
class: "EvaluateProjectJob"
|
||||
queue: message
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EvaluateProjectJob, type: :job do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Loading…
Reference in New Issue