'create activity and send deploy notifications
if they haven\'t been sent'

@classmethod
def notify_if_ready(cls, deploy_id, fetch_complete=False):

    from sentry.models import Activity, Environment, ReleaseCommit, ReleaseHeadCommit
    lock_key = cls.get_lock_key(deploy_id)
    lock = locks.get(lock_key, duration=30)
    with TimedRetryPolicy(10)(lock.acquire):
        deploy = cls.objects.filter(id=deploy_id).select_related('release').get()
        if deploy.notified:
            return
        release = deploy.release
        environment = Environment.objects.get(organization_id=deploy.organization_id, id=deploy.environment_id)
        if (not fetch_complete):
            release_has_commits = ReleaseCommit.objects.filter(organization_id=release.organization_id, release=release).exists()
            if (not release_has_commits):
                if ReleaseHeadCommit.objects.filter(organization_id=release.organization_id, release=release).exists():
                    return
        activity = None
        for project in deploy.release.projects.all():
            activity = Activity.objects.create(type=Activity.DEPLOY, project=project, ident=release.version, data={'version': release.version, 'deploy_id': deploy.id, 'environment': environment.name}, datetime=deploy.date_finished)
        if (activity is not None):
            activity.send_notification()
            deploy.update(notified=True)
