Ok I'm trying to define a dataclass to enqueue a job in redis for a sidekiq worker, the specification of the sidekiq payload requires some attributes something with this format:
{
"class": "SomeWorker",
"queue": "default"
"jid": "b4a577edbccf1d805744efa9", // 12-byte random number as 24 char hex string
"args": [......],
"created_at": 1234567890,
"enqueued_at": 1234567890
}
So I define a dataclass in my python code:
@dataclass
class PusherNotificationJob:
args: Any = None
queue: str = "default"
jid: str = secrets.token_hex(12)
retry: bool = True
created_at: datetime.datetime = time.time()
enqueued_at: datetime.datetime = time.time()
def asdict(self):
return {** self.__dict__, "class": "SomeWorker"}
My problem is that I can't define "class" as an attribute of PusherNotificationJob because it's a reserved word. So I need to define the asdict method to serialize as a dict and add the "class" attribute I added here.
There is a better way to do this?