Skip to content

Commit d5ba883

Browse files
authored
Merge pull request #56 from mmmnmnm/arcsi-stops-error
Arcsi stops error
2 parents abed96c + 6d73c2f commit d5ba883

5 files changed

Lines changed: 31 additions & 15 deletions

File tree

arcsi/api/item.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def view_item(id):
8484

8585
@arcsi.route("/item", methods=["POST"])
8686
def add_item():
87+
no_error = True
8788
if request.is_json:
8889
return make_response(
8990
jsonify("Only accepts multipart/form-data for now, sorry"), 503, headers
@@ -141,7 +142,7 @@ def add_item():
141142
db.session.flush()
142143

143144
if request.files:
144-
process_media(request.files, new_item)
145+
no_error = process_media(request.files, new_item)
145146

146147
# TODO some mp3 error
147148
# TODO Maybe I used vanilla mp3 not from azuracast
@@ -150,8 +151,10 @@ def add_item():
150151
# item_length = item_audio_obj.info.length
151152

152153
db.session.commit()
153-
154-
return make_response(jsonify(item_details_schema.dump(new_item)), 200, headers,)
154+
if no_error:
155+
return make_response(jsonify(item_details_schema.dump(new_item)), 200, headers,)
156+
else:
157+
return "Some error happened, check server logs for details. Note that your media may have been uploaded (to DO and/or Azurcast)."
155158

156159

157160
@arcsi.route("item/<id>/listen", methods=["GET"])
@@ -187,6 +190,7 @@ def delete_item(id):
187190

188191
@arcsi.route("/item/<id>", methods=["POST"])
189192
def edit_item(id):
193+
no_error = True
190194
item_query = Item.query.filter_by(id=id)
191195
item = item_query.first_or_404()
192196
# work around ImmutableDict type
@@ -236,9 +240,12 @@ def edit_item(id):
236240
db.session.flush()
237241

238242
if request.files:
239-
process_media(request.files, item)
243+
no_error = process_media(request.files, item)
240244

241245
db.session.commit()
242-
return make_response(
243-
jsonify(item_details_partial_schema.dump(item)), 200, headers
244-
)
246+
if no_error:
247+
return make_response(
248+
jsonify(item_details_partial_schema.dump(item)), 200, headers
249+
)
250+
return "Some error happened, check server logs for details. Note that your media may have been uploaded (to DO and/or Azurcast)."
251+

arcsi/api/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def broadcast_audio(audio_file_path, item, image_file_path):
6767
if episode_playlist:
6868
# TODO change all other episode airing to false
6969
item.airing = True
70+
return True
71+
return False
72+
7073

7174

7275
def process_audio(play_file, item, image_file_path):
@@ -76,6 +79,7 @@ def process_audio(play_file, item, image_file_path):
7679
Get the extension from file sent to API.
7780
To get the extension we use rsplit w/ maxsplit=1 to make sure we always get the extension even if there is another dot in the filename.
7881
'''
82+
no_error = True
7983
play_file_name = "{}.{}".format(normalise("-".join([item.shows[0].name, item.name])), play_file.filename.rsplit(".", 1)[1])
8084
if play_file.filename != "":
8185
play_file_path = media_path(
@@ -91,13 +95,13 @@ def process_audio(play_file, item, image_file_path):
9195
# TODO fallback img arcsi default img
9296

9397
# ughhhh........
94-
broadcast_audio(play_file_path, item, image_file_path)
98+
no_error = broadcast_audio(play_file_path, item, image_file_path)
9599

96100
if item.archive_lahmastore:
97101
# disdain
98102
archive_audio(play_file_path, item)
99103

100-
return play_file_path
104+
return no_error
101105

102106

103107
def process_image(image_file, item):
@@ -128,11 +132,13 @@ def process_image(image_file, item):
128132

129133

130134
def process_media(request_files, item):
135+
no_error = True
131136
if request_files["image_file"]:
132137
image_file_path = process_image(request_files["image_file"], item)
133138
if request_files["play_file"]:
134139
if image_file_path:
135-
audio_file_path = process_audio(
140+
no_error = process_audio(
136141
request_files["play_file"], item, image_file_path
137142
)
143+
return no_error
138144

arcsi/handler/upload.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def upload(self,):
160160
remaining_byte -= chunk_byte
161161
start += chunk_byte
162162
app.logger.debug("chunk posted! {} bytes remaining".format(remaining_byte))
163+
else:
164+
app.logger.debug("Azuracast response error code: {}, body: {}".format(req.status_code, req.text))
165+
return False #exit while loop when error
163166
except requests.exceptions.RequestException as e:
164167
# max 30 retries
165168
if retry >= 30:
@@ -216,7 +219,7 @@ def assign_playlist(self,):
216219
if not wiped:
217220
app.logger.info("Couldn't wipe playlist")
218221
return False
219-
app.logger.info("Playlist wiped")
222+
app.logger.info("Playlist wiped")
220223
payload = {
221224
"do": "playlist",
222225
"files": [self.play_file_name],
@@ -228,10 +231,10 @@ def assign_playlist(self,):
228231
headers=self.config["headers"],
229232
json=payload,
230233
)
231-
if r.ok:
234+
if r.ok and not self.empty_playlist():
232235
app.logger.info("Add to playlist request successful")
233236
return True
234-
app.logger.info("Add to playlist didn't succeed")
237+
app.logger.debug("Add to playlist didn't succeed")
235238
app.logger.debug("Add to playlist request returned {}".format(r.status_code))
236239
app.logger.debug("Request response \n {}".format(r.content))
237240
return False

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
entrypoint: sh -c 'sleep 60; /app/entrypoint.sh'
3434

3535
db:
36-
image: postgres:10
36+
image: postgres:12
3737
restart: always
3838
volumes:
3939
- ./pg-data/postgres:/var/lib/postgresql/data

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22
python3 -m flask db upgrade
3-
gunicorn --worker-tmp-dir /dev/shm -w 2 --worker-class=gthread --threads 2 -b 0.0.0.0:5666 --log-file /app/aguni.log --log-level info "arcsi:create_app('../config.py')"
3+
gunicorn --worker-tmp-dir /dev/shm -w 2 --worker-class=gthread --threads 2 -b 0.0.0.0:5666 --log-file /app/aguni.log --log-level debug "arcsi:create_app('../config.py')"

0 commit comments

Comments
 (0)