Skip to content
Snippets Groups Projects
Verified Commit 95e9e5f3 authored by Felix Eckhofer's avatar Felix Eckhofer :man_dancing:
Browse files

Move engelsystem logic to conference model

parent 3a34a94e
No related branches found
No related tags found
No related merge requests found
...@@ -8,16 +8,16 @@ module Pretalx ...@@ -8,16 +8,16 @@ module Pretalx
queue_as :default queue_as :default
include ActionView::Helpers include ActionView::Helpers
def import_schedule(conference, url, filedrop_url) def import_schedule(conference)
response = HTTParty.get(url) response = HTTParty.get(conference.schedule_url)
response.success? or return Rails.logger.error "Failed to fetch schedule from #{url}" response.success? or return Rails.logger.error "Failed to fetch schedule from #{conference.schedule_url}"
schedule = JSON.parse(response.body) schedule = JSON.parse(response.body)
return Rails.logger.error "Incomplete JSON received from #{url}" unless return Rails.logger.error "Incomplete JSON received from #{conference.schedule_url}" unless
schedule.dig('schedule', 'conference', 'rooms') && schedule.dig('schedule', 'conference', 'rooms') &&
schedule.dig('schedule', 'conference', 'days') schedule.dig('schedule', 'conference', 'days')
filedrop_index = fetch_filedrop_index(filedrop_url) filedrop_index = fetch_filedrop_index(conference.filedrop_url)
# We keep a local hash of the stages, because the sessions reference stages by name instead of id # We keep a local hash of the stages, because the sessions reference stages by name instead of id
stages = {} stages = {}
...@@ -62,7 +62,7 @@ module Pretalx ...@@ -62,7 +62,7 @@ module Pretalx
end end
end end
session.recorded = !session_data.fetch('do_not_record', false) session.recorded = !session_data.fetch('do_not_record', false)
update_filedrop_data(session, filedrop_index[session.ref_id], filedrop_url) if filedrop_index[session.ref_id] update_filedrop_data(session, filedrop_index[session.ref_id], conference.filedrop_url) if filedrop_index[session.ref_id]
session.save! session.save!
end end
end end
...@@ -75,15 +75,12 @@ module Pretalx ...@@ -75,15 +75,12 @@ module Pretalx
end end
end end
def import_engelsystem_refs(conference, engelsystem_url) def import_engelsystem_refs(conference)
unless translation_angel_id = unless translation_angel_id = conference.fetch_translation_angel_id
fetch_engelsystem(engelsystem_url, "angeltypes") logger.warn("Could not find translation angel id for #{conference.slug}")
&.find { |t| t['name'] == 'Translation Angel' }
&.dig('id')
logger.warn("Could not find angel id for 'Translation Angel' at #{engelsystem_url}")
return return
end end
return unless data = fetch_engelsystem(engelsystem_url, "angeltypes/#{translation_angel_id}/shifts") return unless data = conference.fetch_engelsystem("angeltypes/#{translation_angel_id}/shifts")
shifts = data.each_with_object({}) do |shift, hash| shifts = data.each_with_object({}) do |shift, hash|
starts_at = parse_datetime_or_nil(conference, shift['starts_at']) starts_at = parse_datetime_or_nil(conference, shift['starts_at'])
...@@ -111,8 +108,8 @@ module Pretalx ...@@ -111,8 +108,8 @@ module Pretalx
def perform(conference_slug, *args) def perform(conference_slug, *args)
conference = Conference.find_by(slug: conference_slug) conference = Conference.find_by(slug: conference_slug)
import_schedule(conference, conference.data['schedule_url'], conference.data['filedrop_url']) import_schedule(conference)
import_engelsystem_refs(conference, conference.data['engelsystem_url']) import_engelsystem_refs(conference)
RevisionSet.create!(conference:) RevisionSet.create!(conference:)
heartbeat = conference.data['heartbeat_url'] heartbeat = conference.data['heartbeat_url']
...@@ -121,25 +118,6 @@ module Pretalx ...@@ -121,25 +118,6 @@ module Pretalx
private private
def fetch_engelsystem(engelsystem_url, endpoint)
begin
endpoint_url = engelsystem_url + endpoint
Rails.logger.debug("Querying engelsystem API at #{endpoint_url}")
response = HTTParty.get(
endpoint_url,
headers: {
'Accept' => 'application/json',
"x-api-key" => fetch_credential("engelsystem_token")
},
timeout: 10
)
return response.success? ? JSON.parse(response.body)["data"] : nil
rescue => e
Rails.logger.warn("Engelsystem query for #{endpoint} failed: #{e.message}")
return nil
end
end
def fetch_filedrop_index(filedrop_url) def fetch_filedrop_index(filedrop_url)
return {} unless filedrop_url return {} unless filedrop_url
......
...@@ -26,4 +26,45 @@ class Conference < ApplicationRecord ...@@ -26,4 +26,45 @@ class Conference < ApplicationRecord
def ends_at_in_local_time def ends_at_in_local_time
ends_at.in_time_zone(time_zone || 'UTC') ends_at.in_time_zone(time_zone || 'UTC')
end end
def schedule_url
data['schedule_url']
end
def filedrop_url
data['filedrop_url']
end
def engelsystem_url
data['engelsystem_url']
end
def heartbeat_url
data['heartbeat_url']
end
def fetch_translation_angel_id
fetch_engelsystem("angeltypes")
&.find { |t| t['name'] == 'Translation Angel' }
&.dig('id')
end
def fetch_engelsystem(endpoint)
begin
endpoint_url = engelsystem_url + endpoint
Rails.logger.debug("Querying engelsystem API at #{endpoint_url}")
response = HTTParty.get(
endpoint_url,
headers: {
'Accept' => 'application/json',
"x-api-key" => fetch_credential("engelsystem_token")
},
timeout: 10
)
return response.success? ? JSON.parse(response.body)["data"] : nil
rescue => e
Rails.logger.warn("Engelsystem query for #{endpoint} failed: #{e.message}")
return nil
end
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment