Class: BackupNexus::BackupRunner
- Inherits:
-
Object
- Object
- BackupNexus::BackupRunner
- Defined in:
- app/services/backup_nexus/backup_runner.rb
Class Method Summary collapse
-
.matches_cron?(cron_expression, time) ⇒ Boolean
Check if a cron expression matches the current time.
-
.run(name) ⇒ Object
Run a specific backup config by name.
-
.run_all ⇒ Object
Run all enabled backup configs.
-
.run_scheduled ⇒ Object
Run backups matching a cron schedule.
Class Method Details
.matches_cron?(cron_expression, time) ⇒ Boolean
Check if a cron expression matches the current time
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/services/backup_nexus/backup_runner.rb', line 37 def self.matches_cron?(cron_expression, time) return false if cron_expression.blank? parts = cron_expression.strip.split(/\s+/) return false unless parts.size == 5 minute, hour, day, month, wday = parts match_field(minute, time.min) && match_field(hour, time.hour) && match_field(day, time.day) && match_field(month, time.mon) && match_field(wday, time.wday) end |
.run(name) ⇒ Object
Run a specific backup config by name
6 7 8 9 10 11 |
# File 'app/services/backup_nexus/backup_runner.rb', line 6 def self.run(name) config = BackupNexus::BackupConfig.find_by!(name: name) BackupNexus::BackupService.run(config) rescue ActiveRecord::RecordNotFound { success: false, error: "Backup config '#{name}' not found" } end |
.run_all ⇒ Object
Run all enabled backup configs
14 15 16 17 18 19 20 |
# File 'app/services/backup_nexus/backup_runner.rb', line 14 def self.run_all results = [] BackupNexus::BackupConfig.enabled.find_each do |config| results << BackupNexus::BackupService.run(config) end results end |
.run_scheduled ⇒ Object
Run backups matching a cron schedule
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/backup_nexus/backup_runner.rb', line 23 def self.run_scheduled now = Time.current results = [] BackupNexus::BackupConfig.enabled.where.not(schedule_cron: [nil, ""]).find_each do |config| if matches_cron?(config.schedule_cron, now) results << BackupNexus::BackupService.run(config) end end results end |