@@ -24,6 +24,9 @@ type Envelope struct {
2424type MessageRow struct {
2525 MsgID int64 `gorm:"not null,primaryKey,column:msg_id"`
2626 Message pgtype.JSONB `gorm:"type:jsonb"`
27+ ReadCount int `gorm:"not null,column:read_ct"`
28+ // Visibility timeout
29+ VT pgtype.Timestamptz `gorm:"not null,column:vt"`
2730}
2831
2932type MetaRow struct {
@@ -98,13 +101,12 @@ func toMessage(tenantId int64, in *pgmq.Message) (*models.Message, error) {
98101 }
99102
100103 return & models.Message {
101- ID : in .MsgID ,
102- TenantID : tenantId ,
103- //QueueID: message.QueueID,
104- //DeliverAt: int(message.DeliverAt),
105- //DeliveredAt: int(message.DeliveredAt),
106- //Tries: message.Tries,
107- //MaxTries: message.MaxTries,
104+ ID : in .MsgID ,
105+ TenantID : tenantId ,
106+ DeliverAt : int (in .VT .Unix ()),
107+ Tries : int (in .ReadCount ),
108+ // pgmq has no max retry count; it's always n + 1 here.
109+ MaxTries : int (in .ReadCount ) + 1 ,
108110 Message : []byte (envelope .Body ),
109111 KeyValues : envelope .Headers ,
110112 }, nil
@@ -118,14 +120,13 @@ func rowToMessage(tenantId int64, in *MessageRow) (*models.Message, error) {
118120 }
119121
120122 return & models.Message {
121- ID : in .MsgID ,
122- TenantID : tenantId ,
123- //QueueID: message.QueueID,
124- //DeliverAt: int(message.DeliverAt),
125- //DeliveredAt: int(message.DeliveredAt),
126- //Tries: message.Tries,
127- //MaxTries: message.MaxTries,
128- Message : []byte (envelope .Body ),
123+ ID : in .MsgID ,
124+ TenantID : tenantId ,
125+ DeliverAt : int (in .VT .Time .Unix ()),
126+ Tries : int (in .ReadCount ),
127+ // pgmq has no max retry count; it's always n + 1 here.
128+ MaxTries : int (in .ReadCount ) + 1 ,
129+ Message : []byte (envelope .Body ),
129130 KeyValues : envelope .Headers ,
130131 }, nil
131132}
0 commit comments