Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/jperelli/Redmine-Periodic-Task/issues/25 , https:/… #4

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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