queue

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package queue provides queue management for Notion page synchronization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Type      string    `json:"type"`               // "init" or "update"
	Folder    string    `json:"folder"`             // Folder name
	Pages     []Page    `json:"pages,omitempty"`    // Pages to process (new format)
	PageIDs   []string  `json:"pageIds,omitempty"`  // Page IDs to process (legacy format, deprecated)
	ParentID  string    `json:"parentId,omitempty"` // Parent page ID (for child pages)
	CreatedAt time.Time `json:"createdAt"`          // When this queue entry was created
}

Entry represents a single queue file's content.

func (*Entry) GetPageCount

func (qe *Entry) GetPageCount() int

GetPageCount returns the number of pages in the entry.

func (*Entry) GetPageIDs

func (qe *Entry) GetPageIDs() []string

GetPageIDs returns all page IDs from the entry, supporting both old and new formats.

type Manager

type Manager struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Manager handles queue file operations.

func NewManager

func NewManager(st store.Store, logger *slog.Logger) *Manager

NewManager creates a queue manager.

func (*Manager) CreateEntry

func (qm *Manager) CreateEntry(ctx context.Context, entry Entry) (string, error)

CreateEntry creates new queue file(s) with the next sequential number(s). If entry has more than maxItemsPerQueue pages, it splits into multiple files.

func (*Manager) CreateWebhookEntry

func (qm *Manager) CreateWebhookEntry(ctx context.Context, pageID, folder string) (string, error)

CreateWebhookEntry creates a queue entry for webhook-triggered events. Webhook entries use IDs below webhookIDThreshold (decrementing from 999, 998, ...) to ensure they are processed before regular queue entries.

func (*Manager) DeleteEntry

func (qm *Manager) DeleteEntry(ctx context.Context, filename string) error

DeleteEntry removes an empty queue file.

func (*Manager) GetMinQueueID

func (qm *Manager) GetMinQueueID(ctx context.Context) (int, error)

GetMinQueueID returns the minimum queue ID from existing entries. Returns 0 if there are no entries.

func (*Manager) GetNextQueueNumber

func (qm *Manager) GetNextQueueNumber(ctx context.Context) (int, error)

GetNextQueueNumber returns the next available queue file number for regular (non-webhook) entries. Regular entries start at webhookIDThreshold (1000) and increment upward.

func (*Manager) IsPageQueued

func (qm *Manager) IsPageQueued(ctx context.Context, pageID, queueType string) (bool, error)

IsPageQueued checks if a page is already queued. For type "init", this is used for deduplication. For type "update", duplicates are allowed.

func (*Manager) ListEntries

func (qm *Manager) ListEntries(ctx context.Context) ([]string, error)

ListEntries returns all queue files in sorted order.

func (*Manager) ReadEntry

func (qm *Manager) ReadEntry(ctx context.Context, filename string) (*Entry, error)

ReadEntry reads a queue file.

func (*Manager) SetTransaction added in v0.4.0

func (qm *Manager) SetTransaction(tx store.Transaction)

SetTransaction sets the transaction to use for write operations.

func (*Manager) UpdateEntry

func (qm *Manager) UpdateEntry(ctx context.Context, filename string, entry *Entry) error

UpdateEntry updates a queue file (typically to remove processed pages).

type Page

type Page struct {
	ID         string    `json:"id"`          // Page ID
	LastEdited time.Time `json:"last_edited"` // Last edited time from Notion
}

Page represents a page in the queue with its last edited time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL