def tasks_ps(db=get_boto3_resource('dynamodb'), git_repo=None, git_branch=None, git_tag=None): table = db.Table(_task_table_name) db_filter = (Attr('state').eq(State.pending) | Attr('state').eq(State.downloading) | Attr('state').eq(State.building) | Attr('state').eq(State.testing) | Attr('state').eq(State.pushing)) if git_branch: db_filter = db_filter & Attr('git_branch').eq(git_branch) if git_tag: db_filter = db_filter & Attr('git_tag').eq(git_tag) if db_filter and git_repo: response = table.query( FilterExpression=db_filter, KeyConditionExpression=Key('git_repo').eq(git_repo)) else: response = table.scan() if 'Items' in response: for task in response['Items']: yield Task.from_dict(task)
def reload_task(task, db=get_boto3_resource('dynamodb')): table = db.Table(_task_table_name) response = table.get_item( Key={ 'git_repo': task.git_repo, 'key': '{0}:{1}:{2}'.format(task.created_at.isoformat(), task.git_branch, task.git_tag) }) return Task.from_dict(response['Item'])
def load_task(git_repo, git_branch, git_tag, created_at, db=get_boto3_resource('dynamodb')): table = db.Table(_task_table_name) response = table.get_item( Key={ 'git_repo': git_repo, 'key': '{0}:{1}:{2}'.format(created_at.isoformat(), git_branch, git_tag) }) if 'Item' in response: return Task.from_dict(response['Item']) return None
def tasks_list(db=get_boto3_resource('dynamodb'), git_repo=None, git_branch=None, git_tag=None): table = db.Table(_task_table_name) db_filter = None if git_branch: db_filter = db_filter & Attr('git_branch').eq( git_branch) if db_filter else Attr('git_branch').eq(git_branch) if git_tag: db_filter = db_filter & Attr('git_tag').eq( git_tag) if db_filter else Attr('git_tag').eq(git_tag) if db_filter and git_repo: response = table.query( FilterExpression=db_filter, KeyConditionExpression=Key('git_repo').eq(git_repo)) else: response = table.scan() if 'Items' in response: for task in response['Items']: yield Task.from_dict(task)
def load_all_tasks(db=get_boto3_resource('dynamodb')): table = db.Table(_task_table_name) response = table.scan() if 'Items' in response: for task in response['Items']: yield Task.from_dict(task)