Class: TaskManager::Task
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TaskManager::Task
- Extended by:
- Enumerize
- Defined in:
- app/models/task_manager/task.rb
Class Method Summary collapse
Instance Method Summary collapse
- #assignee ⇒ Object
- #callbacks ⇒ Object
- #expire ⇒ Object
- #finish ⇒ Object
- #next_reminding_at ⇒ Object
-
#remind ⇒ Object
提醒任务执行者,任务即将到期,并且修改任务下次提醒时间。 如果‘next_reminding_at`返回`nil`,则表示该任务不再需要提醒。.
- #remindable? ⇒ Boolean
Class Method Details
.active ⇒ Object
69 70 71 |
# File 'app/models/task_manager/task.rb', line 69 def active where("status = ? OR status = ?", :new, :in_process) end |
.autocompletable ⇒ Object
81 82 83 |
# File 'app/models/task_manager/task.rb', line 81 def autocompletable where(autocompletable: true) end |
.just_expired ⇒ Object
73 74 75 |
# File 'app/models/task_manager/task.rb', line 73 def just_expired active.where("deadline <= ?", Time.now) end |
.remindable ⇒ Object
77 78 79 |
# File 'app/models/task_manager/task.rb', line 77 def remindable active.where("reminding_at <= ?", Time.now) end |
Instance Method Details
#assignee ⇒ Object
21 22 23 |
# File 'app/models/task_manager/task.rb', line 21 def assignee assignable.assignee end |
#callbacks ⇒ Object
25 26 27 |
# File 'app/models/task_manager/task.rb', line 25 def callbacks callables.collect(&:callback) end |
#expire ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/models/task_manager/task.rb', line 54 def expire Task.transaction do callbacks.each do |c| c.call(self) if c.respond_to?(:call) end update_attributes!(status: :expired) end end |
#finish ⇒ Object
64 65 66 |
# File 'app/models/task_manager/task.rb', line 64 def finish update_attributes(finished_at: Time.now, status: :finished) end |
#next_reminding_at ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/task_manager/task.rb', line 36 def next_reminding_at if remindable? seconds = (deadline - reminding_at) / 60 reminding_at.since(seconds) end end |
#remind ⇒ Object
提醒任务执行者,任务即将到期,并且修改任务下次提醒时间。 如果‘next_reminding_at`返回`nil`,则表示该任务不再需要提醒。
46 47 48 49 50 51 52 |
# File 'app/models/task_manager/task.rb', line 46 def remind Task.transaction do assignee.remind_of_expiring_task(self) if assignee.respond_to?(:remind_of_expiring_task) update_attributes!(reminding_at: next_reminding_at) end end |
#remindable? ⇒ Boolean
29 30 31 32 33 34 |
# File 'app/models/task_manager/task.rb', line 29 def remindable? return false if reminding_at.nil? (status == :new || status == :in_process) && (deadline - reminding_at) / 60 >= 2 * 24 * 60 * 60 end |