Skip to content

Having job run on only one node in cluster #624

Description

@krisleech

I noticed that a job is seems to be run either zero, once or more than once on each node in a cluster on my local machine.

The configuration is:

config :export, Export.Scheduler,
  jobs: [
    [
      schedule: "* * * * *", 
      task: fn -> IO.puts("hello #{inspect(DateTime.utc_now())}") end
    ]
  ]

If I start three nodes then I get the following output:

alice node

[debug] file=lib/quantum/execution_broadcaster.ex  Scheduling job for execution
hello ~U[2024-11-05 14:41:00.663749Z]
[debug] file=lib/quantum/executor.ex  Task for job started on node
[debug] file=lib/quantum/executor.ex  Execute started for job
[debug] file=lib/quantum/executor.ex  Execution ended for job

Runs onces.

bob node

[debug] file=lib/quantum/execution_broadcaster.ex  Scheduling job for execution
[debug] file=lib/quantum/executor.ex  Task for job started on node
hello ~U[2024-11-05 14:41:00.049222Z]
[debug] file=lib/quantum/executor.ex  Execute started for job
[debug] file=lib/quantum/executor.ex  Execution ended for job
hello ~U[2024-11-05 14:41:00.567387Z]
[debug] file=lib/quantum/executor.ex  Execute started for job
[debug] file=lib/quantum/executor.ex  Execution ended for job

Runs twice.

kris node

[debug] file=lib/quantum/execution_broadcaster.ex  Scheduling job for execution
[debug] file=lib/quantum/executor.ex  Task for job started on node

Runs zero times.

I tried adding the Quantum.RunStrategy.Random as the run strategy (which I thought was the default anyway) but got the following error:

config :export, Export.Scheduler,
  run_strategy: Quantum.RunStrategy.Random
  jobs: [
    [
      schedule: "* * * * *", 
      task: fn -> IO.puts("hello #{inspect(DateTime.utc_now())}") end
    ]
  ]
# (FunctionClauseError) no function clause matching in Quantum.RunStrategy.Random.normalize_config!/1
            (quantum 3.5.3) lib/quantum/run_strategy/random.ex:33: Quantum.RunStrategy.Random.normalize_config!(nil)
            (elixir 1.17.3) lib/keyword.ex:1144: Keyword.update!/4
            (elixir 1.17.3) lib/keyword.ex:1148: Keyword.update!/4
            (export 0.1.0) /Users/kris/dev/nimbus/apps/abacus/deps/quantum/lib/quantum.ex:416: Export.Scheduler.__new_job__/2

Any help would be much appreciated!

I am using libcluster to enrol the nodes in a cluster and can see in Node.list() that this is the case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions