def initialize_external_job(job_id, *args, **kwargs):
    """
        Create external jobs when job has been initialized.
    """
    job = Job.objects.get(id=job_id)
    handler = get_job_handler(job)
    handler.init_job(**kwargs)
    def run(self, *args, **kwargs):
        """ Main task function.
        """
        try:
            unmapped_samples = self.get_unmapped_samples()
            jobs = self.get_jobs(unmapped_samples)
            tc = make_tagapi_client()

            log.info('SampleVotingManager: Gathered samples and jobs.')
            for job, new_samples, initialized in jobs:
                try:
                    handler = get_job_handler(job)
                    if initialized:
                        handler.update_voting(tc=tc, samples=new_samples)
                    else:
                        handler.init_voting(tc=tc, samples=new_samples)
                except Exception, e:
                    log.exception(
                        'SampleVotingManager: Error in job %d: %s.' % (job.id, e)
                    )
                    continue
        except Exception, e:
            log.exception(
                'SampleVotingManager: exception while all jobs: %s.' % e
            )
def btm_send_to_human(sample_id, **kwargs):
    '''
        Updates appropriate BTM job with new sample.
    '''
    btm = BeatTheMachineSample.objects.get(id=sample_id)
    job = btm.job
    handler = get_job_handler(job)
    handler.update_btm(btm_samples=[btm])
def initialize_btm_job(job_id, topic, description, no_of_urls, **kwargs):
    """
        Initializes BTM task for given job.
    """
    job = Job.objects.get(id=job_id)
    handler = get_job_handler(job)
    handler.init_btm_gather(topic=topic, description=description,
        no_of_urls=no_of_urls)
def voting_hit_change(job_id, old_hit, new_hit, **kwargs):
    job = Job.objects.get(id=job_id)
    handler = get_job_handler(job)
    handler.voting_hit_changed(old=old_hit, new=new_hit)
def btm_voting_hit_change(job_id, old_hit, new_hit, **kwargs):
    job = Job.objects.get(id=job_id)
    handler = get_job_handler(job)
    handler.btm_voting_hit_changed(old=old_hit, new=new_hit)
def sample_gathering_hit_change(job_id, old_hit, new_hit, **kwargs):
    job = Job.objects.get(id=job_id)
    handler = get_job_handler(job)
    handler.sample_gathering_hit_changed(old=old_hit, new=new_hit)