Princemaple Together Save Abandoned

Group things together!

Project README

Together

Hex.pm Documentation

Group actions that can be handled / responded to later together

What for?

  • group notifications to be sent in one email
    • cancel the previously queued email if another event happens within a short period (type: debounce)
  • make heavy operations happen less often, i.e. refresh some global statistics
    • allow only 1 operation per certain period (type: throttle)
  • protect some write api
    • additonally you can choose to use the first value in a period (keep: first)
    • or the last value in the period (keep: last)

Installation

The package can be installed as:

Add together to your list of dependencies in mix.exs:

def deps do
  [{:together, "~> 0.5"}]
end

Since ex_shards uses shards, if you are still using applications instead of the new extra_applications, which infers applications list, make sure that shards is added to the list:

def application do
  [applications: [:shards]]
end

How to use

Start Together.Supervisor to use it

  • Start with application configs
supervisor(Together.Supervisor, [])
  • Start with configs passed in
supervisor(Together.Supervisor, [workers: ..., store: ...])

Make calls to the worker process:

Together.process(binary_name, "something_unique", some_func)
Together.process(pid, "some_unique_name_or_id", a_function)
Together.process(Together.Worker, "id", Module, :func, [arg1, arg2, ...])

Example config

config :together,
  workers: [
    # name is required, can be anything, prefer strings
    [name: "throttled_job", delay: 30_000, type: :throttle],
    [name: "debounced_job", delay: 5_000, type: :debounce],
    [name: "keep_first_job", keep: :first],
    # etc
  ],
  # omissible, if you don't want to change anything
  store: [
    # name for the Store process
    name: MyApp.Together.Store,
    # name for the ExShards main process
    shards_name: MyApp.Together.Store.Shards,
    # for distributed ets
    scope: :g,
    # nodes in the cluster, will use `Node.list` if omitted
    nodes: [:"[email protected]", :"[email protected]"]
  ]

More ideas

  • keep: all (seems to be touching gen_stage territory)
Open Source Agenda is not affiliated with "Princemaple Together" Project. README Source: princemaple/together
Stars
35
Open Issues
0
Last Commit
1 year ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating