Skip to content

Commit

Permalink
Add recover-status-timestamps command
Browse files Browse the repository at this point in the history
  • Loading branch information
netkan-bot committed Nov 17, 2019
1 parent 5df86da commit 5cba2c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions netkan/netkan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ def restore_status(filename):
click.echo('Done!')


@click.command()
@click.option(
'--ckanmeta-remote', envvar='CKANMETA_REMOTE',
help='Path/URL/SSH to Metadata Repo',
)
def recover_status_timestamps(ckanmeta_remote):
ModStatus.recover_timestamps(init_repo(ckanmeta_remote, '/tmp/CKAN-meta'))


@click.command()
@click.option(
'--cluster', help='ECS Cluster running the service'
Expand Down Expand Up @@ -294,6 +303,7 @@ def auto_freezer(netkan_remote, token, repo, user, days_limit, key):
netkan.add_command(dump_status)
netkan.add_command(export_status_s3)
netkan.add_command(restore_status)
netkan.add_command(recover_status_timestamps)
netkan.add_command(redeploy_service)
netkan.add_command(clean_cache)
netkan.add_command(download_counter)
Expand Down
19 changes: 19 additions & 0 deletions netkan/netkan/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,22 @@ def restore_status(cls, filename):
time.sleep(1)

batch.save(ModStatus(**item))

@classmethod
def last_indexed_from_git(cls, ckanmeta_repo, identifier):
try:
return parse(ckanmeta_repo.git.log('--', identifier, format='%aI').split("\n")[0])
except Exception as exc: # pylint: disable=broad-except
logging.error('Unable to recover last_indexed for %s',
identifier, exc_info=exc)
return None

@classmethod
def recover_timestamps(cls, ckanmeta_repo):
with cls.batch_write() as batch:
for mod in cls.scan(rate_limit=5):
if not mod.last_indexed:
mod.last_indexed = cls.last_indexed_from_git(
ckanmeta_repo, mod.ModIdentifier)
if mod.last_indexed:
batch.save(mod)

0 comments on commit 5cba2c1

Please sign in to comment.