Background Jobs

Qualified Name Type Release

apoc.periodic.list

apoc.periodic.list - list all jobs

Procedure

APOC Core

apoc.periodic.submit

apoc.periodic.submit('name',statement,params) - creates a background job which executes a Cypher statement once. The parameter 'params' is optional and can contain query parameters for the Cypher statement

Procedure

APOC Core

apoc.periodic.countdown

apoc.periodic.countdown('name',statement,repeat-rate-in-seconds) creates a background job that will repeatedly execute the given Cypher statement until it returns 0.

Procedure

APOC Core

  • The jobs list is updated every 10s for finished jobs.

Additional configuration

It is possible to override the default thread pool size (processors*2), which might be useful if many jobs are running at the same time:

apoc.jobs.pool.num_threads=10

Many periodic procedures rely on a scheduled executor that has a pool of threads with a default fixed size (processors/4, at least 1). It is possible to configure the pool size using the following configuration property:

apoc.jobs.scheduled.num_threads=10

Countdown Example

The Cypher statement must return a numeric value and it should decrement (like a monotonically decreasing function). It is repeatedly executed until the return value reaches 0. For example, define a counter with a numeric property:

CREATE (counter:Counter) SET counter.c = 10

and decrement this property by 1 each second:

CALL apoc.periodic.countdown('decrement',"MATCH (counter:Counter) SET counter.c = counter.c - 1 RETURN counter.c as count", 1)