apoc.periodic.repeat

Details

Syntax

apoc.periodic.repeat(name, statement, rate [, config ]) :: (name, delay, rate, done, cancelled)

Description

Runs a repeatedly called background job. To stop this procedure, use apoc.periodic.cancel.

Input arguments

Name

Type

Description

name

STRING

The name of the job.

statement

STRING

The Cypher statement to run.

rate

INTEGER

The delay in seconds to wait between each job execution.

config

MAP

{ params = {} :: MAP, cancelOnError = true :: BOOLEAN } The default is: {}. Introduced in APOC 2025.08 Cypher 25

Return arguments

Name

Type

Description

name

STRING

The name of the job.

delay

INTEGER

The delay on the job.

rate

INTEGER

The rate of the job.

done

BOOLEAN

If the job has completed.

cancelled

BOOLEAN

If the job has been cancelled.

Usage Examples

We can create 10 Person nodes every second by running the following query:

CALL apoc.periodic.repeat(
  "create-people",
  "UNWIND range(1,10) AS id CREATE (:Person {uuid: apoc.create.uuid()})",
   1
);
Results
name delay rate done cancelled

"create-people"

0

1

FALSE

FALSE

We can check how many nodes have been created by running the following query:

MATCH (:Person)
RETURN count(*) AS count;
Results
count

110

If you want to cancel this job, you can use the apoc.periodic.cancel procedure and specify the name of the job as the argument.

Handling errors

By default, if a query run with apoc.periodic.repeat returns an error, the task is canceled and will not be run again. This behavior can be overridden using the config parameter: cancelOnError.

The following query will create a Person node with a random id property. However, when the expression toInteger(3 * rand()) evaluates to 0, a division by zero error is thrown. By setting cancelOnError to false, this error will be ignored, and the task will be retried after one second.

CALL apoc.periodic.repeat(
  "sometimes-create-people",
  "CREATE (:Person {id: 1 / toInteger(3 * rand())})",
   1,
  { cancelOnError: false }
);
Results
name delay rate done cancelled

"sometimes-create-people"

0

1

FALSE

FALSE