1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from celery
import registry
22 from mediagoblin
import mg_globals
23 from mediagoblin
.processing
import mark_entry_failed
24 from mediagoblin
.processing
.task
import ProcessMedia
27 _log
= logging
.getLogger(__name__
)
30 def run_process_media(entry
):
31 process_media
= registry
.tasks
[ProcessMedia
.name
]
33 process_media
.apply_async(
34 [unicode(entry
.id)], {},
35 task_id
=entry
.queued_task_id
)
36 except BaseException
as exc
:
37 # The purpose of this section is because when running in "lazy"
38 # or always-eager-with-exceptions-propagated celery mode that
39 # the failure handling won't happen on Celery end. Since we
40 # expect a lot of users to run things in this way we have to
43 # ... not completely the diaper pattern because the
44 # exception is re-raised :)
45 mark_entry_failed(entry
.id, exc
)
46 # re-raise the exception
50 def handle_push_urls(request
):
51 if mg_globals
.app_config
["push_urls"]:
52 feed_url
= request
.urlgen(
53 'mediagoblin.user_pages.atom_feed',
55 user
=request
.user
.username
)
57 'hub.mode': 'publish',
59 hubdata
= urllib
.urlencode(hubparameters
)
61 "Content-type": "application/x-www-form-urlencoded",
62 "Connection": "close"}
63 for huburl
in mg_globals
.app_config
["push_urls"]:
64 hubrequest
= urllib2
.Request(huburl
, hubdata
, hubheaders
)
66 hubresponse
= urllib2
.urlopen(hubrequest
)
67 except urllib2
.HTTPError
as exc
:
68 # This is not a big issue, the item will be fetched
69 # by the PuSH server next time we hit it
71 "push url %r gave error %r", huburl
, exc
.code
)
72 except urllib2
.URLError
as exc
:
74 "push url %r is unreachable %r", huburl
, exc
.reason
)