data_source_plugin: add DataSource.timeout field to limit the time taken to download a data source
This commit is contained in:
parent
904aa53b85
commit
42bd357c96
|
@ -58,7 +58,8 @@ class Data(object):
|
||||||
}
|
}
|
||||||
request = requests.get(self.final_url, headers=headers,
|
request = requests.get(self.final_url, headers=headers,
|
||||||
verify=self.data_source.verify_certificate,
|
verify=self.data_source.verify_certificate,
|
||||||
allow_redirects=self.data_source.allow_redirects)
|
allow_redirects=self.data_source.allow_redirects,
|
||||||
|
timeout=self.data_source.timeout)
|
||||||
request.raise_for_status()
|
request.raise_for_status()
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
logger.warning('HTTP Error %s when loading datasource %s from'
|
logger.warning('HTTP Error %s when loading datasource %s from'
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from south.utils import datetime_utils as datetime
|
||||||
|
from south.db import db
|
||||||
|
from south.v2 import SchemaMigration
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(SchemaMigration):
|
||||||
|
|
||||||
|
def forwards(self, orm):
|
||||||
|
# Adding field 'DataSource.timeout'
|
||||||
|
db.add_column(u'data_source_plugin_datasource', 'timeout',
|
||||||
|
self.gf('django.db.models.fields.IntegerField')(default=10),
|
||||||
|
keep_default=False)
|
||||||
|
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
# Deleting field 'DataSource.timeout'
|
||||||
|
db.delete_column(u'data_source_plugin_datasource', 'timeout')
|
||||||
|
|
||||||
|
|
||||||
|
models = {
|
||||||
|
'cms.cmsplugin': {
|
||||||
|
'Meta': {'object_name': 'CMSPlugin'},
|
||||||
|
'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||||
|
'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
|
||||||
|
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||||
|
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||||
|
'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
|
||||||
|
'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
|
||||||
|
'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
|
||||||
|
'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||||
|
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
|
||||||
|
},
|
||||||
|
'cms.placeholder': {
|
||||||
|
'Meta': {'object_name': 'Placeholder'},
|
||||||
|
'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
|
||||||
|
},
|
||||||
|
u'data_source_plugin.datasource': {
|
||||||
|
'Meta': {'ordering': "('name',)", 'object_name': 'DataSource'},
|
||||||
|
'allow_redirects': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||||
|
'hash_algo': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '16', 'blank': 'True'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'mime_type': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
|
||||||
|
'name': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
|
||||||
|
'signature_key': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '128', 'blank': 'True'}),
|
||||||
|
'timeout': ('django.db.models.fields.IntegerField', [], {'default': '10'}),
|
||||||
|
'url': ('django.db.models.fields.URLField', [], {'max_length': '1024'}),
|
||||||
|
'verify_certificate': ('django.db.models.fields.BooleanField', [], {'default': 'True'})
|
||||||
|
},
|
||||||
|
u'data_source_plugin.datasourceplugin': {
|
||||||
|
'Meta': {'object_name': 'DataSourcePlugin', 'db_table': "u'cmsplugin_datasourceplugin'"},
|
||||||
|
u'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'limit': ('django.db.models.fields.IntegerField', [], {'default': '10'}),
|
||||||
|
'refresh': ('django.db.models.fields.IntegerField', [], {'default': '60'}),
|
||||||
|
'template_source': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
|
||||||
|
},
|
||||||
|
u'data_source_plugin.plugindatasource': {
|
||||||
|
'Meta': {'ordering': "('order', 'id')", 'object_name': 'PluginDataSource'},
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
|
||||||
|
'plugin': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sources'", 'to': u"orm['data_source_plugin.DataSourcePlugin']"}),
|
||||||
|
'source': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'plugins'", 'to': u"orm['data_source_plugin.DataSource']"})
|
||||||
|
},
|
||||||
|
u'data_source_plugin.rawinlinetemplateplugin': {
|
||||||
|
'Meta': {'object_name': 'RawInlineTemplatePlugin', 'db_table': "u'cmsplugin_rawinlinetemplateplugin'"},
|
||||||
|
u'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'template_source': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['data_source_plugin']
|
|
@ -48,6 +48,10 @@ class DataSource(models.Model):
|
||||||
allow_redirects = models.BooleanField(verbose_name=_('allows HTTP redirections'),
|
allow_redirects = models.BooleanField(verbose_name=_('allows HTTP redirections'),
|
||||||
help_text=_('it can improve latencies to forbid redirection follow'),
|
help_text=_('it can improve latencies to forbid redirection follow'),
|
||||||
default=True)
|
default=True)
|
||||||
|
timeout = models.IntegerField(verbose_name=_('timeout'),
|
||||||
|
default=10,
|
||||||
|
help_text=_('time in second to wait before '
|
||||||
|
'failing to download a datasource'))
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.signature_key and not self.hash_algo:
|
if self.signature_key and not self.hash_algo:
|
||||||
|
|
Reference in New Issue