Sha256: c70061bbf309b032005c6b4e361b323261062929be7d950d722a808d9a733069

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

push: >
  INSERT INTO queue(id, name, fire_at, value)
  VALUES (HEX(RANDOMBLOB(32)), $1, (IFNULL(UNIXEPOCH('subsec'), UNIXEPOCH()) + $2), $3)
  RETURNING id, name;

pop: >
  DELETE FROM queue
  WHERE name != '_dead'
  AND (name, fire_at, id)
  IN (
      SELECT name, fire_at, id FROM queue
      WHERE name = IFNULL($1, 'default')
      AND fire_at <= IFNULL(UNIXEPOCH('subsec'), UNIXEPOCH())
      ORDER BY fire_at ASC
      LIMIT IFNULL($2, 1)
  )
  RETURNING id, value;

repush: >
  INSERT INTO queue(id, name, fire_at, value)
  VALUES ($1, $2, (IFNULL(UNIXEPOCH('subsec'), UNIXEPOCH()) + $3), $4)
  RETURNING name;

delete: >
  DELETE FROM queue
  WHERE id = $1
  RETURNING value;

count: >
  SELECT COUNT(*)
  FROM queue
  WHERE IIF($1 IS NULL, 1, name = $1);

clear: >
  DELETE FROM queue
  WHERE IIF($1 IS NULL, 1, name = $1)
  RETURNING id;

info: >
  SELECT 
    name, 
    COUNT(*) AS count, 
    AVG(IFNULL(UNIXEPOCH('subsec'), UNIXEPOCH()) - created_at) AS avg, 
    MIN(IFNULL(UNIXEPOCH('subsec'), UNIXEPOCH()) - created_at) AS min, 
    MAX(IFNULL(UNIXEPOCH('subsec'), UNIXEPOCH()) - created_at) AS max
  FROM queue 
  GROUP BY name 
  ORDER BY count DESC;

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
litequeue-0.2.1 lib/litequeue/statements.sql.yml