Class: Snails::QueueOccurrence

Inherits:
Sqlx::Base show all
Defined in:
runtime/snails/queue_occurrence.rbs,
runtime/snails/queue_occurrence.rb

Constant Summary collapse

COLUMNS =

The projected columns — the ledger's identity and its write stamp, with a reader generated for each (the hash-backed accessor loop: one list, only_columns derives from it).

%w[job_name scheduled_at created_at].each { |column| define_method(column) { read_attribute(column) } }

Constants inherited from Sqlx::Base

Sqlx::Base::TIMESTAMP_COLUMNS

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Sqlx::Base

all, boolean_columns, date_columns, from_row, json_columns, transaction

Methods included from Sqlx::Query

#count, #create!, #delete!, #delete_all!, #exists?, #fetch_many, #find, #find_by, #find_by!, #find_by_sql, #find_each, #find_in_batches, #projection, #row_by_sql, #rows_by_sql, #update!, #update_all!, #upsert_all!, #where_clause, #write

Methods included from Sqlx::Model

#enum

Methods included from Sqlx::Row

#initialize, #read_attribute

Instance Attribute Details

#created_at ⇒ Time? (readonly)

Returns the value of attribute created_at.

Returns:



7
8
9
# File 'runtime/snails/queue_occurrence.rbs', line 7

def created_at
  @created_at
end

#job_name ⇒ String (readonly)

Returns the value of attribute job_name.

Returns:



5
6
7
# File 'runtime/snails/queue_occurrence.rbs', line 5

def job_name
  @job_name
end

#scheduled_at ⇒ Time? (readonly)

Returns the value of attribute scheduled_at.

Returns:



6
7
8
# File 'runtime/snails/queue_occurrence.rbs', line 6

def scheduled_at
  @scheduled_at
end

Class Method Details

.datetime_columns ⇒ Object

Time columns: identity (scheduled_at) and stamp (created_at) come back as Time; the list replaces the default pair.



26
# File 'runtime/snails/queue_occurrence.rb', line 26

def self.datetime_columns = %w[scheduled_at created_at]

.insert!(job_name, scheduled_at, now) ⇒ void

put one occurrence on the ledger. The primary key is the idempotency: a duplicate (job_name, scheduled_at) raises instead of overwriting, and the caller turns that into "already queued". The row has no id column (the key IS the pair), which is why the ledger brings its own insert instead of the id-based create! re-read.

Parameters:

  • job_name (String) —

    the job's name — the stored constant path

  • scheduled_at (Time) —

    the interval's start

  • now (Time) —

    the created stamp

Raises:



40
# File 'runtime/snails/queue_occurrence.rb', line 40

def self.insert!: (String job_name, Time scheduled_at, Time now) -> void

.only_columns ⇒ Object



22
# File 'runtime/snails/queue_occurrence.rb', line 22

def self.only_columns = COLUMNS.map { |c| c.to_sym }

.prune_before!(scheduled_before, limit:) ⇒ Integer

retention delete for the ledger in bounded batches: occurrences past the window go, recent ones stay, and one call removes at most limit rows (the caller repeats — Snails::QueuePruneJob owns the loop). The pair IN the subquery is the ledger's primary key, so the delete needs no id column; it works on both backends.

Parameters:

  • scheduled_before (Time) —

    the retention cutoff

  • limit (Integer) —

    the most rows one call deletes (positive)

Returns:

  • (Integer) —

    the number of rows deleted (0 when none matched)

Raises:

  • (ArgumentError) —

    limit is not a positive Integer



56
# File 'runtime/snails/queue_occurrence.rb', line 56

def self.prune_before!: (Time scheduled_before, limit: Integer) -> Integer

.table_name ⇒ Object



15
# File 'runtime/snails/queue_occurrence.rb', line 15

def self.table_name = "snails_queue_occurrences"