Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rescheduled 🗓️
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3lingo
rescheduled 🗓️
Commits
95e9e5f3
Verified
Commit
95e9e5f3
authored
3 months ago
by
Felix Eckhofer
Browse files
Options
Downloads
Patches
Plain Diff
Move engelsystem logic to conference model
parent
3a34a94e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/jobs/pretalx/import_job.rb
+12
-34
12 additions, 34 deletions
app/jobs/pretalx/import_job.rb
app/models/conference.rb
+41
-0
41 additions, 0 deletions
app/models/conference.rb
with
53 additions
and
34 deletions
app/jobs/pretalx/import_job.rb
+
12
−
34
View file @
95e9e5f3
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
app/models/conference.rb
+
41
−
0
View file @
95e9e5f3
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment