Example #1
0
async def run(node_id):
    # Any replicated object with get/set functions
    data_id = raftos.Replicated(name='data_id')

    # Dict-like object: data.update(), data['key'] etc
    data = raftos.ReplicatedDict(name='data')

    # List-like object: data_list.append(), data_list[-1]
    data_list = raftos.ReplicatedList(name='data_list')

    while True:
        # We can also check if raftos.get_leader() == node_id
        await raftos.wait_until_leader(node_id)

        await asyncio.sleep(2)

        current_id = random.randint(1, 1000)
        data_map = {
            str(current_id): {
                'created_at': datetime.now().strftime('%d/%m/%y %H:%M')
            }
        }

        await data_id.set(current_id)
        await data.update(data_map)
        await data_list.append(data_map)
Example #2
0
 async def run_node(self):
     data_id = raftos.Replicated(name='data_id')
     data = raftos.ReplicatedDict(name='data')
     data_list = raftos.ReplicatedList(name='data_list')
     while True:
         await raftos.wait_until_leader(self.node)
         await asyncio.sleep(2)
         current_id = random.randint(1, 1000)
         data_map = {
             str(current_id): {
                 'created_at':
                 datetime.datetime.now().strftime('%d/%m/%y %H:%M')
             }
         }
         await data_id.set(current_id)
         await data.update(data_map)
         await data_list.append(data_map)
Example #3
0
class Class:
    data = raftos.Replicated(name='data')