我得到了一个将数据发布到cassandra表的方法。不知何故,我能够(有时)添加不应该发生的重复行。下面是我为此编写的方法。我正在检查,如果该名称已经存在,如果是,没有数据应张贴。
有什么明显的遗漏吗?
print(args)
jm = Jenkins()
#print(json.dumps(args, sort_keys=True, indent=4))
for i in args:
jm.name = i['fullDisplayName']
jm.result = i['result']
jm.jobnumber = str(i['id'])
jm.executor = i['executor']
jm.duration = str(i['duration'])
jm.time_stamp = str(i['timestamp'])
jm.url = i['url']
jm.id = str(uuid.uuid4())
check_if_table_is_empty = len(Jenkins.objects.all())
if (check_if_table_is_empty is 0):
Jenkins.create(name=jm.name, result=jm.result, jobnumber=jm.jobnumber, executor=jm.executor,
duration=jm.duration, time_stamp=jm.time_stamp, url=jm.url, id=jm.id)
return jm.id
else:
for data in Jenkins.objects.all():
if (data['name'] == jm.name):
return data['id']
else:
jm.save()
return jm.id
id | duration | executor | jobnumber | name | result | time_stamp | url
--------------------------------------+----------+----------+-----------+----------------------------+---------+---------------+---------------------------------------------------------
5dd7ba97-fd93-4a54-bce6-002502f0e96b | 7912 | null | 10 | alten-training-develop #10 | ABORTED | 1530273379763 |**********************
7d8209f3-d5fd-4fa3-9c6c-1f5030928407 | 30222 | null | 6 | adbridge-develop #6 | FAILURE | 1529907888157 | **********************
a43f00df-a6cf-45d9-9190-fe06cfa28327 | 30222 | null | 6 | adbridge-develop #6 | FAILURE | 1529907888157 | **********************
servicename | address | matchtype | samplingtype | servicetype
------------------------+----------------------+------------+--------------+-------------
alten-training-develop |*****.*****.se:8081 | ['RegEx1'] | HTTP | Jenkins
adbridge-develop |*****.****.se:8081 | ['RegEx1'] | HTTP | Jenkins
暂无答案!
目前还没有任何答案,快来回答吧!