Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pau na importação de dados #15

Open
leonardofl opened this issue Feb 4, 2015 · 3 comments
Open

Pau na importação de dados #15

leonardofl opened this issue Feb 4, 2015 · 3 comments

Comments

@leonardofl
Copy link
Member

Na hora de executar o script de importação, obtive essa saída no log do radar (/var/log/radar/radar.log):

INFO 2015-02-03 22:08:22,614 Invocando importador de cdep assincronamente
INFO 2015-02-03 22:08:22,637 Invocando importador de conv assincronamente
INFO 2015-02-03 22:08:22,671 Invocando importador de cmsp assincronamente
INFO 2015-02-03 22:08:22,671 IMPORTANDO DADOS DA CAMARA DOS DEPUTADOS
INFO 2015-02-03 22:08:22,672 Procurando em 1991
INFO 2015-02-03 22:08:22,707 Invocando importador de sen assincronamente
ERROR 2015-02-03 22:09:37,838 Exception handling request for /analises/analise/cmsp/
Traceback (most recent call last):
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "./analises/views.py", line 42, in analise
    models.CasaLegislativa, nome_curto=nome_curto_casa_legislativa)
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 115, in get_object_or_404
    raise Http404('No %s matches the given query.' % queryset.model._meta.object_name)
Http404: No CasaLegislativa matches the given query.
INFO 2015-02-03 22:09:38,370 40 PLs encontrados
INFO 2015-02-03 22:09:41,046 IMPORTANDO DADOS DO SENADO
INFO 2015-02-03 22:09:41,069 IMPORTANDO SENADORES
INFO 2015-02-03 22:09:41,072 Importando senadores da legislatura 52

E esse é o pau que dá quando tento fazer as análises:

ERROR 2015-02-03 22:13:29,172 Exception handling request for /analises/json_analise/sen/BIENIO/
Traceback (most recent call last):
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "./analises/views.py", line 73, in json_analise
    casa_legislativa, periodicidade, lista_de_palavras_chave)
  File "./analises/analise.py", line 70, in __init__
    self.ini = self.periodos[0].ini
IndexError: list index out of range
INFO 2015-02-03 22:13:38,868 40 MPVs encontrados
ERROR 2015-02-03 22:13:38,885 Exception handling request for /analises/analise/cdep/
Traceback (most recent call last):
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "./analises/views.py", line 42, in analise
    models.CasaLegislativa, nome_curto=nome_curto_casa_legislativa)
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 115, in get_object_or_404
    raise Http404('No %s matches the given query.' % queryset.model._meta.object_name)
Http404: No CasaLegislativa matches the given query.
ERROR 2015-02-03 22:13:42,087 Exception handling request for /analises/analise/cdep/
Traceback (most recent call last):
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "./analises/views.py", line 42, in analise
    models.CasaLegislativa, nome_curto=nome_curto_casa_legislativa)
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 115, in get_object_or_404
    raise Http404('No %s matches the given query.' % queryset.model._meta.object_name)
Http404: No CasaLegislativa matches the given query.
ERROR 2015-02-03 22:13:47,223 Exception handling request for /analises/json_analise/cmsp/BIENIO/
Traceback (most recent call last):
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "./analises/views.py", line 73, in json_analise
    casa_legislativa, periodicidade, lista_de_palavras_chave)
  File "./analises/analise.py", line 70, in __init__
    self.ini = self.periodos[0].ini
IndexError: list index out of range

Uma suspeita é que não dê pra fazer a importação paralela de todas as casas, talvez tenha q rolar uma importação por vez. Pra testar isso é só alterar o script pra fazer a importação de apenas uma casa e ver oq rola.

@leonardofl leonardofl changed the title Pau na importação cmsp Pau na importação de dados Feb 4, 2015
@leonardofl
Copy link
Member Author

Avaliando melhor: comentei algumas chamadas e deixei o script de importação importando só uma casa legislativa.
O log imprime "Invocando importador de conv assincronamente", e nada mais,
Ou seja, parece que a thread assíncrona não está sendo disparada.
(https://github.com/radar-parlamentar/radar/blob/master/radar_parlamentar/importadores/views.py)
Juntando isso com o fato de q possivelmente não seja mesmo boa ideia fazer as importações em paralelo, creio que o certo seja usar um sistema de filas (celery, p ex).
Estou pesquisando.

@leonardofl
Copy link
Member Author

Usando o Celery agora!

0774bf6
128ffc7

Parece que resolveu o pau, e agora só roda uma importação de cada vez.
Só falta testar com a importação da cdep.

@leonardofl
Copy link
Member Author

Funcionando, mas parece q as vezes ainda dá pau...

Numa 1a execução foi blz, mas numa 2a tentativa, deu pau na importação do senado:

[2015-02-18 00:18:03,427: ERROR/MainProcess] Task importadores.celery.importar_assincronamente[661f2410-288d-4f1f-99f8-6edfab72612e] raised unexpected: DatabaseError('terminating connection due to administrator command\nSSL connection has been closed unexpectedly\n',)
Traceback (most recent call last):
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/ubuntu/radar/repo/radar_parlamentar/importadores/celery.py", line 45, in importar_assincronamente
    importador.main([nome_curto_casa_legislativa])
  File "/home/ubuntu/radar/repo/radar_parlamentar/importadores/importador.py", line 16, in main
    importador_senado.main()
  File "/home/ubuntu/radar/repo/radar_parlamentar/importadores/sen.py", line 440, in main
    importer.importar_votacoes()
  File "/home/ubuntu/radar/repo/radar_parlamentar/importadores/sen.py", line 328, in importar_votacoes
    self._from_xml_to_bd(xml_file)
  File "/home/ubuntu/radar/repo/radar_parlamentar/importadores/sen.py", line 297, in _from_xml_to_bd
    votos = self._votos_from_tree(votos_tree, votacao)
  File "/home/ubuntu/radar/repo/radar_parlamentar/importadores/sen.py", line 198, in _votos_from_tree
    votacao.data, nome_senador)
  File "modelagem/models.py", line 356, in find
    for leg in legs:
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/db/models/query.py", line 118, in _result_iter
    self._fill_cache()
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/db/models/query.py", line 892, in _fill_cache
    self._result_cache.append(self._iter.next())
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/db/models/query.py", line 291, in iterator
    for row in compiler.results_iter():
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "/home/ubuntu/radar/venv_radar/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
DatabaseError: terminating connection due to administrator command
SSL connection has been closed unexpectedly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant