import json


def retry_job(info):
    """
    Create job json for job retry.
    """

    # build params
    params = {}
    params['id'] = info['job_id']
    params['rule_name'] = info['rule']['rule_name']
    params['username'] = info['rule']['username']
    kwargs = json.loads(info['rule']['kwargs'])
    rule_hit = info['rule_hit']
    params['job'] = rule_hit['_source']['job']
    job_id = params['job'].get('job_id', None)
    if isinstance(job_id, str) and job_id.startswith('action-retry_job'):
        name = job_id
    else:
        name = 'action-retry_job-%s' % job_id
    job = {
        'type': 'retry_job',
        'name': name,
        'tag': params['rule_name'],
        'username': params['username'],
        'params': params,
        'localize_urls': []
    }

    return job