timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.04k stars 157 forks source link

Different retention for __state__completed____pgboss__maintenance jobs #159

Closed leventov closed 3 years ago

leventov commented 4 years ago

It would be nice to support retention period for __state__completed__ jobs different from the default (30 days).

timgit commented 4 years ago

Good idea. thx

timgit commented 4 years ago

Completion jobs inherit the retention according to the following, in order of priority.

  1. Retention set on the original job
  2. Global retention config
  3. 30 days

The easiest way of implementing what you're asking appears to be a new config setting on each publish (something like completionRetention*), so you can pick a different retention for the completion job then replace item 1 above in the assignment priority. It's a bit verbose, but very easy to reason about.

I'll keep brainstorming on a global retention policy specifically for completion jobs that makes it easy to understand for those relying on onComplete(). What I'm trying to avoid is someone not understanding how retention could potentially be in conflict with onComplete(), since it's possible that a combination of settings could remove jobs from a queue before subscriptions can fetch them.

ibash commented 3 years ago

+1 to flexibility here

I deployed pg boss to a free database and got a row limit warning. Given this is a dev instance, not a huge deal to make it purge more often, but was a bit of a surprise.

=> select name, count(*) from pgboss.archive group by name order by count desc;
                   name                    | count
-------------------------------------------+-------
 __state__completed____pgboss__cron        |  3242
 __pgboss__cron                            |  2524
 __state__completed____pgboss__maintenance |  1378
 __pgboss__maintenance                     |  1249
 notify-ask                                |    12
 __state__completed__notify-ask            |    12
(6 rows)