Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Answer

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...