-
Notifications
You must be signed in to change notification settings - Fork 150
Inconsistent track
callback behaviour
#300
Comments
The reason your callback is called multiple times is due to #308 The reason You can force a flush using |
Another option is to disable automatic flushing and rely on manual flushing only as described in #305 (comment) |
It doesn't matter how long you wait because the promise for the |
Ah I see. The fact that the callback is called twice is due to a bug (#308). The callback receives the So if you want to denounce using the presence of if (batch === undefined) {
return resolve();
} |
From the docs:
https://segment.com/docs/connections/sources/catalog/libraries/server/node/#batching The current behaviour doesn't match what is described in the documentation. I expected the callback to be called after the message is flushed, but that does not always happen. In my case, I am not interested in knowing when the message has been put in the queue. Are there any plans to change that? |
FYI I am not affiliated with Segment or The callback is always called and it is always after the message has been flushed (sent to the server). Due to a bug, sometimes it is called a second time, but again, both times are always after the message has been flushed. Once from line 266 and sometimes again from 267: Lines 265 to 268 in 70f24fe
The callback is always called once with an undefined |
@yo1dog Sorry, I thought you were part of the Segment team. Thanks for all your help/feedback.
Yes, that seems to produce the correct behaviour that I am looking for. And I don't actually need the batch data. I'm not sure why I was under the impression that it was being called with It seems to me that they should just get rid of line 267 and pass I am going to close this issue since it is essentially a duplicate of #308 and #231. |
See my previous comment here: #231
I may have been incorrect in saying that the callback is being called before the message is actually flushed. That was just an assumption based on the fact that the callback is being called twice and in the first call, batch is undefined.
Here is some code that demonstrates the behaviour I described:
I am using the Salesforce integration, but I doubt the actual messages/events matter.
And here is the output:
As you can see, in the second call to
createAccountAndContact
, thetrack
callback is only called once for theupsert-contact-by-email
event, and so thePromise.all
never resolves because of theif (batch !== undefined)
check in the callback (the first call tocreateAccountAndContact
actually works as expected because the client doesn't batch on its very first message).I could remove the
if (batch !== undefined)
check, and the script would finish, but that may cause issues if I was triggering some code that should only run once in the callback. Also, thebatch
data is alwaysundefined
on the first callback call, and my code could potentially need that value.Another way to get the script to finish is to set
flushAt
equal to1
, but then there is no batching.Ideally, the
track
callback would only be called once, and thebatch
value would never beundefined
.Thanks.
The text was updated successfully, but these errors were encountered: