Cassandra中的重复行

时间:2019-04-17 11:38:18

标签: python jenkins cassandra celery

我有一种方法可以将数据发布到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

0 个答案:

没有答案