Skip to content

Commit

Permalink
Merge 112a823 into c28a166
Browse files Browse the repository at this point in the history
  • Loading branch information
czue committed Mar 1, 2019
2 parents c28a166 + 112a823 commit 0f4e33f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion commcare_export/checkpoint.py
Expand Up @@ -12,6 +12,7 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

from commcare_export.exceptions import DataExportException
from commcare_export.writers import SqlMixin

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -86,7 +87,8 @@ def set_final_checkpoint(self):

def _set_checkpoint(self, checkpoint_time, final):
logger.info('Setting %s checkpoint: %s', 'final' if final else 'batch', checkpoint_time)
checkpoint_time = checkpoint_time or datetime.datetime.utcnow()
if not checkpoint_time:
raise DataExportException('Tried to set an empty checkpoint. This is not allowed.')
with session_scope(self.Session) as session:
session.add(Checkpoint(
id=uuid.uuid4().hex,
Expand Down
7 changes: 5 additions & 2 deletions commcare_export/commcare_hq_client.py
Expand Up @@ -141,15 +141,18 @@ def iterate_resource(resource=resource, params=params):
else:
more_to_fetch = False

self.checkpoint(paginator, batch)
self.checkpoint(paginator, batch)

return RepeatableIterator(iterate_resource)

def checkpoint(self, paginator, batch):
from commcare_export.commcare_minilinq import DatePaginator
if self._checkpoint_manager and isinstance(paginator, DatePaginator):
since_date = paginator.get_since_date(batch)
self._checkpoint_manager.set_batch_checkpoint(checkpoint_time=since_date)
if since_date:
self._checkpoint_manager.set_batch_checkpoint(checkpoint_time=since_date)
else:
logger.warning('Failed to get a checkpoint date from a batch of data.')


class MockCommCareHqClient(object):
Expand Down

0 comments on commit 0f4e33f

Please sign in to comment.