Skip to content

Commit

Permalink
Gerando dump com comando python dumpdata em json Resolves radar-parla…
Browse files Browse the repository at this point in the history
…mentar#465

Co-authored-by: Felipe Osório <[email protected]>
Co-authored-by: Harrison Pedro <[email protected]>
  • Loading branch information
3 people committed May 17, 2018
1 parent 9e3a048 commit 1353592
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions radar_parlamentar/cron/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def do(self):
logger.info('DbDumperJob foi chamado.')
weekday = date.today().weekday()
# segunda é o zero
dumper = DbDumper()
dumper.dump()
if weekday == 0:

logger.info('DbDumperJob fazendo dump do banco.')
else:
logger.info('Hoje não é o dia. DbDumperJob só trabalha às segundas.')
Expand All @@ -115,10 +118,12 @@ class DbDumper():
# Teste de DbDumper: 1o apaga arquivo se existir, executa, verifica se arquivo foi criado
# publicar radar/base no docker hub

DUMP_FILE = "/radar/radar_parlamentar/radar_parlamentar/static/db-dump/radar.sql"
DUMP_FILE = "/radar/radar_parlamentar/radar_parlamentar/static/db-dump/radar.json"

def dump(self):
dump_command = 'pg_dump -h postgres -U radar -d radar -W --inserts -t modelagem_* -f %s' % DbDumper.DUMP_FILE
dump_command = 'python manage.py dumpdata --indent 2 \
--exclude auth.permission --exclude contenttypes\
> %s' % DbDumper.DUMP_FILE
os.system(dump_command)
#compress_command = 'bzip2 -9 -f %s' % DbDumper.DUMP_FILE
#os.system(compress_command)
Expand Down
1 change: 1 addition & 0 deletions radar_parlamentar/radar_parlamentar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@

CRON_CLASSES = [
'cron.jobs.ImportadorJob',
'cron.jobs.DbDumperJob'
]

if os.getenv('RADAR_TEST'):
Expand Down

0 comments on commit 1353592

Please sign in to comment.