GithubHelp home page GithubHelp logo

Comments (3)

whitfin avatar whitfin commented on July 21, 2024

This is a bit of a pain, because hooks have to be built and started before the worker actually is... so the irony is the worker doesn't even exist during start up.

So... Need to think of another way around it. Considering an option to pass into a hook of requires_worker: true which causes the worker to ping { :worker, worker } on startup to allow the hook to configure itself accordingly.

This is kinda gross, but it does lend itself to backwards compatibility well.

defmodule MyModule.WorkerHook do
  use Cachex.Hook

  def init(args) when is_map(args) do
    { :ok, args }
  end

  def handle_modify({ :worker, worker }, state) do
    { :ok, Map.put(state, :worker, worker) }
  end

  def handle_notify(_action, state) do
    { :ok, IO.inspect(state) }
  end
end

from cachex.

whitfin avatar whitfin commented on July 21, 2024

Ok I have this working now... I'll just neaten it up a bit and get a PR in. It's not the nicest interface, but I expect it to be less frequently used, so it shouldn't matter too much.

from cachex.

whitfin avatar whitfin commented on July 21, 2024

Hit a bug with overriding handle_call/2 to give myself access to handle_modify/2 (namely that it breaks too easily). For this reason, just going to provide changes to handle_call/2 and document well.

from cachex.

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.