smartcontractkit / external-initiator

Initiate Chainlink job runs from external sources

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initiate a new poll if the stored answer is older than the poll timer and there's no poll in progress

boxhock opened this issue · comments

34de4dc#diff-9e0f29fe3564bf3da63eeb25d28b4f6e1732571f9af6dcb7ff1d11775b7d7376R218-R226

Introduced this check (but probably when the result is older that this interval something might have gone wrong with polling anyway).

As an implicit convention, results that have been fetched before "now - pollTimer - adapterTimeout", are considered non-recent and not suitable for reporting.

I think this should be sufficient, at least for the PoC.

if time.Now().After(fm.latestResultTimestamp.Add(fm.config.PollInterval).Add(fm.config.AdapterTimeout))

We can simplify this:

if time.Since(fm.latestResultTimestamp) > fm.config.PollInterval+fm.config.AdapterTimeout

I also think we should move the mutex, because currently a poll can be in progress - but the FM will take the old value instead. Ideally, it'd wait for the poll that's already in progress to complete before returning that value, instead of deferring to the "old" value.

Changed the syntax + remove the mutex. A new poll is taking place before heartbeat, so result should be fresh anyway, might just result in an extra polling.

Since polling time is small in general, and heartbeat should take place once in a while, probably we shouldn't have issues with it. But if you think we can use a channel or something similar to indicate when a poll is in progress, feel free to add the change.

I think we should still have mutex to avoid the problem of a heartbeat and poller possibly triggering a poll around the same time. I can work on this issue later on.

OK, leaving it as it is now in case we need to use channel instead of mutex.

Handled in #130