def _sync_from_artifact_store(jobstep):
    """Checks and creates new artifacts from the artifact store."""
    url = '{base}/buckets/{jobstep_id}/artifacts/'.format(
        base=current_app.config.get('ARTIFACTS_SERVER'),
        jobstep_id=jobstep.id.hex,
    )
    job = jobstep.job

    try:
        res = requests.get(url, timeout=ARTIFACTS_REQUEST_TIMEOUT_SECS)
        res.raise_for_status()
        artifacts = res.json()
        for artifact in artifacts:
            # Artifact name is guaranteed to be unique in an artifact store bucket.
            artifact_name = artifact['name']
            artifact_path = artifact['relativePath']
            if artifact_name in LOGSOURCE_WHITELIST:
                _, created = get_or_create(LogSource, where={
                    'name': artifact_name,
                    'job': job,
                    'step': jobstep,
                }, defaults={
                    'project': job.project,
                    'date_created': job.date_started,
                    'in_artifact_store': True,
                })

                if created:
                    try:
                        db.session.commit()
                    except IntegrityError as err:
                        db.session.rollback()
                        current_app.logger.error(
                            'DB Error while inserting LogSource %s',
                            artifact_name, exc_info=True)

                # If this artifact is a logsource, don't add it to the list of
                # test artifacts.
                continue

            art, created = get_or_create(Artifact, where={
                # Don't conflict with same artifacts uploaded by other means (Jenkins/Mesos)
                'name': ARTIFACTSTORE_PREFIX + artifact_path,
                'step_id': jobstep.id,
                'job_id': jobstep.job_id,
                'project_id': jobstep.project_id,
            })
            if created:
                art.file.storage = 'changes.storage.artifactstore.ArtifactStoreFileStorage'
                filename = 'buckets/{jobstep_id}/artifacts/{artifact_name}'.format(
                    jobstep_id=jobstep.id.hex,
                    artifact_name=artifact_name,
                )
                art.file.save(None, filename)
                try:
                    db.session.add(art)
                    db.session.commit()
                except IntegrityError, err:
                    db.session.rollback()
                    current_app.logger.error(
                        'DB Error while inserting artifact %s: %s', filename, err)
    except (ConnectionError, __HOLE__, SSLError, Timeout) as err:
        if isinstance(err, HTTPError) and err.response is not None and err.response.status_code == 404:
            # While not all plans use the Artifact Store, 404s are normal and expected.
            # No sense in reporting them.
            pass
        else:
            # Log to sentry - unable to contact artifacts store
            current_app.logger.warning('Error fetching url %s: %s', url, err, exc_info=True)
    except Exception, err:
        current_app.logger.error('Error updating artifacts for jobstep %s: %s', jobstep, err, exc_info=True)
        raise err
dataset/ETHPy150Open dropbox/changes/changes/jobs/sync_job_step.py/_sync_from_artifact_store