1

In my application, I'm queueing client requests which the server will process one by one. But I only want the server to process requests that are 30 seconds old. So I created a unique path that clients push to and the server watches on child_added. Is there a way to get the timestamp when the child is added or any other metadata?

I know i can make the clients put the timestamp in the value but I don't want the clients to control the value because it can cause a security risk.

Update: clearly there is no firebase controlled timestamp or any other metadata attached to the node. The answer below is wrong.

2 Answers 2

6

You may use firebase server TIMESTAMP ,

firebaseRef.on('child_added', function(childSnapshot, prevChildName) { // Update Firebase.ServerValue.TIMESTAMP on childSnapshot }); 
Sign up to request clarification or add additional context in comments.

6 Comments

This will mark the time when the message was received by the server. So if the server is offline and then wakes up to process messages it does not know how long they have been sitting in the queue.
Huh? The Firebase servers are real-time; they don't sleep. And it's unclear what you are expecting here. You don't want the clients to control the timestamp, but you also don't want the server to control the timestamp? Who is going to control it then?
@Kato Firebase. Firebase never sleeps but my servers do and when they wake up they only want to process messages that are new.
Check out this question for more on only processing new messages. But really, if you are using the queue model, they should be removed when processed. Thus, there should never be old items.
Firebase.ServerValue.TIMESTAMP is set by Firebase when the data is entered. It is not set by your worker script or the client. Thus even if your server script is offline the timestamp will be set correctly. Also, this isn't an argument; everyone here is trying to help you; adjust your tone accordingly or you'll find volunteers few and far between.
|
0

Although not a direct answer to the question but the firebase queue which was introduced today can be used to achieve what was stated in the question. The _state_changed flag will serve as the timestamp.

https://www.firebase.com/blog/2015-05-15-introducing-firebase-queue.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.