Skip to content

Commit

Permalink
feat(models): represents a role in the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianLusina committed Mar 1, 2023
1 parent 8b65566 commit 5d4b962
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions konsensus/models/role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Callable
from node import Node


class Role:
"""Represents roles corresponding to the cluster"""
def __init__(self, node: Node) -> None:
self.node = node
self.node.register(self)
self.running = True
self.logger = node.logger.getChild(type(self).__name__)

def set_timer(self, seconds: int, callback: Callable):
return self.node.network.set_timer(self.node.address, seconds, lambda: self.running and callback())

def stop(self):
self.running = False
self.node.unregister(self)

0 comments on commit 5d4b962

Please sign in to comment.