Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

neo4j - How to auto update node attributes in ne04j after a specific time period

Is there a way to update an existing attribute in a node to a new value after a specific time period passes ?

For example: Node 'Offer' has the below attributes

  1. Offer Name (String)
  2. Offer ID (Numeric)
  3. CREATED_ON (Timestamp)
  4. IS_VALID ('Yes'/'No')

Process:

  1. When an initial "Offer" is created IS_VALID value is "Yes"
  2. After 7 days of creation IS_VALID value should be set to "No" automatically for each of the offers

I know that there is TTL , but I don't want my node to be deleted after 7 days, rather the attribute to be updated to "No" from "Yes"

Is there any way I can achieve this in Neo4j?

question from:https://stackoverflow.com/questions/65895260/how-to-auto-update-node-attributes-in-ne04j-after-a-specific-time-period

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use apoc procedure calls for scheduling background jobs. apoc.periodic.schedule() makes sense in your case.

CALL apoc.periodic.schedule('offerValidater', 
"MATCH (n: Offer) WHERE apoc.date.currentTimestamp() - n.CREATED_ON > 604800000 SET n.IS_VALID = 'No'", 
86400)

Here I assumed that offer.CREATED_ON is in epoch milliseconds. If you are using other format timestamps you need to do a comparison accordingly. offerValidater routine is scheduled to run with a delay of 86400 seconds (1 day).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...