Class: Kronos::Storage::MongoDb
- Inherits:
-
Object
- Object
- Kronos::Storage::MongoDb
- Defined in:
- lib/kronos/storage/mongo_db.rb
Overview
:reek:UtilityFunction:
Constant Summary collapse
- SHEDULED_TASK_MODEL =
Mongo::Model::ScheduledTaskModel
- REPORT_MODEL =
Mongo::Model::ReportModel
Instance Method Summary collapse
- #pending?(task) ⇒ Boolean
- #register_report(report) ⇒ Object
- #remove(task_id) ⇒ Object
- #remove_reports_for(task_id) ⇒ Object
- #reports ⇒ Object
- #resolved_tasks ⇒ Object
- #schedule(scheduled_task) ⇒ Object
- #scheduled_tasks ⇒ Object
Instance Method Details
#pending?(task) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/kronos/storage/mongo_db.rb', line 50 def pending?(task) # Checks if task has any pending scheduled task (where scheduled_task.next_run > Time.now) query = SHEDULED_TASK_MODEL.where(task_id: task.id) query.exists? && query.first.next_run > Time.now end |
#register_report(report) ⇒ Object
39 40 41 42 43 |
# File 'lib/kronos/storage/mongo_db.rb', line 39 def register_report(report) # Removes any Kronos::Report with same task ID and saves the one in parameter remove_reports_for(report.task_id) REPORT_MODEL.create(report_params(report)) end |
#remove(task_id) ⇒ Object
29 30 31 32 |
# File 'lib/kronos/storage/mongo_db.rb', line 29 def remove(task_id) # Removes scheduled tasks with task_id SHEDULED_TASK_MODEL.where(task_id: task_id).destroy_all end |
#remove_reports_for(task_id) ⇒ Object
45 46 47 48 |
# File 'lib/kronos/storage/mongo_db.rb', line 45 def remove_reports_for(task_id) # Removes reports with task_id REPORT_MODEL.where(task_id: task_id).destroy_all end |
#reports ⇒ Object
34 35 36 37 |
# File 'lib/kronos/storage/mongo_db.rb', line 34 def reports # Returns all previous Kronos::Report that were saved using #register_report REPORT_MODEL.all end |
#resolved_tasks ⇒ Object
24 25 26 27 |
# File 'lib/kronos/storage/mongo_db.rb', line 24 def resolved_tasks # Returns a list of task ids that where resolved (where scheduled_task.next_run <= Time.now) SHEDULED_TASK_MODEL.where(:next_run.lte => Time.now).pluck(:task_id) end |
#schedule(scheduled_task) ⇒ Object
18 19 20 21 22 |
# File 'lib/kronos/storage/mongo_db.rb', line 18 def schedule(scheduled_task) # Removes any Kronos::ScheduledTask with same task ID and saves the one in parameter remove(scheduled_task.task_id) SHEDULED_TASK_MODEL.create(scheduled_task_params(scheduled_task)) end |
#scheduled_tasks ⇒ Object
13 14 15 16 |
# File 'lib/kronos/storage/mongo_db.rb', line 13 def scheduled_tasks # Returns all current Kronos::ScheduledTask, resolved or pending SHEDULED_TASK_MODEL.all end |