Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j query run at specific time

Currently, I'm making an application with asp.net core and neo4j graph database.

My application provides an account registration system, which send an activation code to user registered email and after 24 hours, if user doesn't click on the active link, the account will be deleted.

My question is : can I write a trigger in neo4j graph database to automatically runs after 24 hours after a node has been created to check whether it has been verified or not and delete it if it hasn't.

Can anyone help me please ?

Thank you :)

like image 682
Redplane Avatar asked May 29 '16 03:05

Redplane


2 Answers

You can use apoc job management:

1) Create user:

CREATE (U:User {created_at: timestamp(), activated: false}) 

2) Running periodic task (every hour), which takes a list of non-activated users, and checks the activation time, and remove those who do not activate account within 24 hours:

CALL apoc.periodic.repeat('name',
    'MATCH (U:User {activated: false}) 
         WHERE timestamp() - U.created_at > 24 * 60 * 60 * 1000
     DETACH DELETE U', 
60 * 60)
like image 199
stdob-- Avatar answered Oct 21 '22 06:10

stdob--


There are multiple solutions that handle this :

First one is a neo4j plugin called neo4j-expire where you can set a time-to-live timestamp on a node and this node will be automatically expired/deleted by the plugin at the given time :

https://github.com/graphaware/neo4j-expire

The second solution is to create a Cypher query that performs this check and register it with the job management procedures available in neo4j-apoc https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_job_management

like image 20
Christophe Willemsen Avatar answered Oct 21 '22 07:10

Christophe Willemsen