mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 19:34:09 +08:00
3c59106bac
This reverts commit c29a4dddc1
.
We're doing a beta bump soon so un-revert this after that is done.
36 lines
996 B
Ruby
36 lines
996 B
Ruby
|
|
module Jobs
|
|
class ScheduleBackup < Jobs::Scheduled
|
|
daily at: 0.hours
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
return unless SiteSetting.enable_backups? && SiteSetting.automatic_backups_enabled?
|
|
|
|
if latest_backup = Backup.all[0]
|
|
date = File.ctime(latest_backup.path).getutc.to_date
|
|
return if (date + SiteSetting.backup_frequency.days) > Time.now.utc.to_date
|
|
end
|
|
|
|
Jobs.cancel_scheduled_job(:create_backup)
|
|
|
|
time_of_day = Time.parse(SiteSetting.backup_time_of_day)
|
|
seconds = time_of_day.hour.hours + time_of_day.min.minutes + rand(10.minutes)
|
|
|
|
Jobs.enqueue_in(seconds, :create_backup)
|
|
rescue => e
|
|
notify_user(e)
|
|
raise
|
|
end
|
|
|
|
def notify_user(ex)
|
|
post = SystemMessage.create_from_system_user(
|
|
Discourse.system_user,
|
|
:backup_failed,
|
|
logs: "#{ex}\n" + ex.backtrace.join("\n")
|
|
)
|
|
post.topic.invite_group(Discourse.system_user, Group[:admins])
|
|
end
|
|
end
|
|
end
|