2013-02-20 04:16:50 +08:00
|
|
|
require_dependency 'discourse_hub'
|
|
|
|
require_dependency 'discourse_updates'
|
|
|
|
|
|
|
|
module Jobs
|
2013-08-08 01:25:05 +08:00
|
|
|
class VersionCheck < Jobs::Scheduled
|
|
|
|
recurrence { daily }
|
2013-02-20 04:16:50 +08:00
|
|
|
|
|
|
|
def execute(args)
|
2013-07-31 00:11:51 +08:00
|
|
|
if SiteSetting.version_checks? and (DiscourseUpdates.updated_at.nil? or DiscourseUpdates.updated_at < 1.minute.ago)
|
2013-03-25 23:35:33 +08:00
|
|
|
begin
|
2013-08-17 05:28:36 +08:00
|
|
|
should_send_email = (SiteSetting.new_version_emails and DiscourseUpdates.missing_versions_count and DiscourseUpdates.missing_versions_count == 0)
|
|
|
|
|
2013-03-25 23:35:33 +08:00
|
|
|
json = DiscourseHub.discourse_version_check
|
|
|
|
DiscourseUpdates.latest_version = json['latestVersion']
|
|
|
|
DiscourseUpdates.critical_updates_available = json['criticalUpdates']
|
|
|
|
DiscourseUpdates.missing_versions_count = json['missingVersionsCount']
|
2013-07-03 23:06:07 +08:00
|
|
|
DiscourseUpdates.updated_at = Time.zone.now
|
2013-08-17 05:28:36 +08:00
|
|
|
|
|
|
|
if should_send_email and json['missingVersionsCount'] > 0
|
|
|
|
message = VersionMailer.send_notice
|
|
|
|
Email::Sender.new(message, :new_version).send
|
|
|
|
end
|
2013-03-25 23:35:33 +08:00
|
|
|
rescue => e
|
|
|
|
raise e unless Rails.env == 'development' # Fail version check silently in development mode
|
|
|
|
end
|
2013-02-21 23:19:02 +08:00
|
|
|
end
|
2013-02-20 04:16:50 +08:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|