Giter Site home page Giter Site logo

Comments (2)

bradleyayers avatar bradleyayers commented on May 19, 2024 4

I've gone this route (queuing jobs via a trigger) and have had a great success with it. I use singletonkey and startin (where startin is the throttle window). I'm using it to update my search index when records change that would affect the index. It's turned out to be extremely easy to setup!

In case it's helpful to others, here's what I'm using:

create or replace function dovetail_private.queuenoteforsearchindexing(note_id uuid) returns void as $$
  insert into dovetail_pgboss.job (id, name, startin, singletonkey, data)
  values
    (
      uuid_generate_v1(),
      'SEARCH_INDEXING_INDEX_NOTE',
      '10 seconds'::interval,
      -- Using the note ID as the singletonkey serves to debounce based on note.
      $1::text,
      json_build_object('noteId', $1::text)
    )
  on conflict do nothing
$$ language sql strict security definer;

create function dovetail_private.note$queuesearchindexing() returns trigger as $$
begin
  perform dovetail_private.queuenoteforsearchindexing(new.id);
  -- result is ignored since this is an AFTER trigger
  return null;
end;
$$ language plpgsql strict;

create trigger afterupdate050$queuesearchindexing after update
  on dovetail.note
  for each row
  when (
    new.title is distinct from old.title
    or new.deleted is distinct from old.deleted
    or new.type is distinct from old.type
    or new.content_version is distinct from old.content_version
    or new.ranges::text is distinct from old.ranges::text
  )
  execute procedure dovetail_private.note$queuesearchindexing();

from pg-boss.

timgit avatar timgit commented on May 19, 2024

👍 I have defaults defined for most fields, so unless you need to change them, they can be excluded from COPY or INSERT.

from pg-boss.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.