Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jan 6, 2020
1 parent afc6856 commit fcc46e1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/periodictask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class Periodictask < ActiveRecord::Base
]

def generate_issue(now = Time.now)
Time.zone = User.current.time_zone
if project.try(:active?)
# Copy subject and description and replace variables
subj = parse_macro(subject.try(:dup), now)
desc = parse_macro(description.try(:dup), now)

issue = Issue.new(:project_id => project_id, :tracker_id => tracker_id || project.trackers.first.try(:id), :category_id => issue_category_id,
:assigned_to_id => assigned_to_id, :author_id => author_id,
:subject => subj, :description => desc)
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ en:
no_members_in_project: This project has no members
no_categories_in_project: This project has no categories
label_subject: Subject
label_next_run_date: Next run date (yyyy-mm-dd hh:mm:ss)
label_next_run_date: Next run date (yyyy-mm-dd hh:mm:ss timezone)
label_edit_periodic_task: Edit Periodic Task
label_new_periodic_task: New Periodic Task
label_no_members_in_project: This project has no members
Expand Down
4 changes: 2 additions & 2 deletions config/locales/zh.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Coding:UTF-8
# Chinese strings go here for Rails i18n
# Chinese strings go here for Rails i18n
# Translated from English strings by Tomora.
zh:
label_tracker: 跟踪
Expand All @@ -8,7 +8,7 @@ zh:
no_members_in_project: 该项目没有成员
no_categories_in_project: 该项目没有类别
label_subject: 主题
label_next_run_date: 下一运行日(yyyy-mm-dd hh:mm:ss)
label_next_run_date: 下一运行日(yyyy-mm-dd hh:mm:ss timezone)
label_edit_periodic_task: 编辑周期任务
label_new_periodic_task: 新建周期任务
label_no_members_in_project: 该项目没有成员
Expand Down
10 changes: 7 additions & 3 deletions lib/scheduled_tasks_checker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ScheduledTasksChecker

def self.checktasks!
now = Time.now
Time.zone = User.current.time_zone
now = Time.zone.now
Periodictask.where("next_run_date <= ? ", now).each do |task|

# replace variables (set locale from shell)
Expand All @@ -18,11 +20,13 @@ def self.checktasks!
interval = task.interval_number
units = task.interval_units.downcase
if units == "business_day"
task.next_run_date = task.interval_number.business_day.after(now)
next_run_date = task.interval_number.business_day.after(Time.zone.now)
else
interval_steps = ((now - task.next_run_date) / interval.send(units)).ceil
task.next_run_date += (interval * interval_steps).send(units)
next_run_date += (interval * interval_steps).send(units)
end
next_run_date = next_run_date.change({ hour: Time.zone.now.hour.to_i, min: Time.zone.now.min.to_i, sec: Time.zone.now.sec.to_i })
task.next_run_date = next_run_date
else
msg = "Project is missing or closed"
Rails.logger.error "ScheduledTasksChecker: #{msg}"
Expand Down

0 comments on commit fcc46e1

Please sign in to comment.