'Synchronize with a repository, called from scheduler task
@param repository: the repository Row
@return: True if successful, False if there was an error'

def synchronize(self, repository):

    current.log.debug(('S3Sync:    synchronize    %s' % repository.url))
    log = self.log
    repository_id = repository.id
    error = None
    if (repository.apitype == 'filesync'):
        if (not repository.path):
            error = 'No    path    set    for    repository'
    elif (not repository.url):
        error = 'No    URL    set    for    repository'
    if error:
        log.write(repository_id=repository_id, resource_name=None, transmission=None, mode=log.NONE, action='connect', remote=False, result=self.log.FATAL, message=error)
        return False
    db = current.db
    s3db = current.s3db
    ttable = s3db.sync_task
    query = ((ttable.repository_id == repository_id) & (ttable.deleted != True))
    tasks = db(query).select()
    connector = S3SyncRepository(repository)
    error = connector.login()
    if error:
        log.write(repository_id=repository_id, resource_name=None, transmission=log.OUT, mode=log.LOGIN, action='login', remote=True, result=log.FATAL, message=error)
        return False
    s3 = current.response.s3
    s3.synchronise_uuids = connector.synchronise_uuids
    success = True
    for task in tasks:
        mtime = None
        if (task.mode in (1, 3)):
            (error, mtime) = connector.pull(task, onconflict=self.onconflict)
        if error:
            success = False
            current.log.debug(('S3Sync:    %s    PULL    error:    %s' % (task.resource_name, error)))
            continue
        if (mtime is not None):
            task.update_record(last_pull=mtime)
        mtime = None
        if (task.mode in (2, 3)):
            (error, mtime) = connector.push(task)
        if error:
            success = False
            current.log.debug(('S3Sync:    %s    PUSH    error:    %s' % (task.resource_name, error)))
            continue
        if (mtime is not None):
            task.update_record(last_push=mtime)
        current.log.debug(('S3Sync.synchronize:    %s    done' % task.resource_name))
    s3.synchronise_uuids = False
    db((s3db.sync_repository.id == repository_id)).update(last_connected=datetime.datetime.utcnow())
    return success
