'Extract new updates from the local database and send
them to the peer repository (active push)
@param task: the synchronization task (sync_task Row)
@return: tuple (error, mtime), with error=None if successful,
else error=message, and mtime=modification timestamp
of the youngest record sent'

def push(self, task):

    repository = self.repository
    log = repository.log
    error = None
    result = None
    tablename = task.resource_name
    if (tablename == 'mixed'):
        resource = None
        mixed = True
    else:
        try:
            resource = current.s3db.resource(tablename, include_deleted=True)
        except SyntaxError:
            result = log.FATAL
            error = msg = sys.exc_info()[1]
        mixed = False
    if (not result):
        outfile = self._output_file(task)
        if (not outfile):
            result = log.ERROR
            if repository.path:
                error = msg = 'No    pattern    configured    for    output    file    name'
            else:
                error = msg = 'No    file    path    configured    for    repository'
    if (not result):
        adapter = None
        backend = repository.backend
        if (not backend):
            backend = 'eden'
        backend = ('s3.sync_adapter.%s' % backend)
        try:
            name = 'S3SyncAdapter'
            api = getattr(__import__(backend, fromlist=[name]), name)
        except ImportError:
            result = log.FATAL
            error = msg = ('Unsupported    back-end:    %s' % backend)
        else:
            adapter = api(repository)
    if result:
        log.write(repository_id=repository.id, resource_name=tablename, transmission=log.OUT, mode=log.PUSH, action=None, remote=False, result=result, message=msg)
        return (error, None)
    from ..s3import import S3ImportItem
    update_policy = task.update_policy
    if (not update_policy):
        update_policy = S3ImportItem.POLICY.NEWER
    if (update_policy not in ('THIS', 'OTHER')):
        msince = task.last_push
    else:
        msince = None
    filters = current.sync.get_filters(task.id)
    error = None
    mtime = None
    action = 'data    export'
    output = adapter.send(resource, msince=msince, filters=filters, mixed=mixed, pretty_print=task.human_readable)
    status = output.get('status')
    if (status in (log.ERROR, log.FATAL)):
        result = status
        msg = output.get('message')
        if (not msg):
            msg = 'Error    while    exporting    data'
        error = msg
    else:
        response = output.get('response')
        path = repository.path
        if (not os.path.exists(path)):
            try:
                os.makedirs(path)
            except OSError:
                result = log.FATAL
                error = msg = sys.exc_info()[1]
        if (not error):
            try:
                action = ('open    %s' % outfile)
                with open(outfile, 'w') as target:
                    target.write(response)
            except IOError:
                result = log.FATAL
                error = msg = sys.exc_info()[1]
            else:
                result = log.SUCCESS
                msg = ('Data    successfully    written    to    %s' % outfile)
                if resource:
                    msg = ('%s    (%s    records)' % (msg, resource.results))
                    mtime = resource.muntil
                else:
                    mtime = current.request.utcnow
    log.write(repository_id=repository.id, resource_name=task.resource_name, transmission=log.OUT, mode=log.PUSH, action=action, remote=False, result=result, message=msg)
    return (error, mtime)
