onyx

FYI: alternative Onyx :onyx: chat is at <https://gitter.im/onyx-platform/onyx> ; log can be found at <https://clojurians-log.clojureverse.org/onyx/index.html>
lucasbradstreet 2018-04-17T00:10:11.000270Z

Back.

lucasbradstreet 2018-04-17T00:11:03.000131Z

We have designed the output plugin interfaces to allow you to implement async requests like this in a sensible way.

lucasbradstreet 2018-04-17T00:11:22.000218Z

You can see it in play in the sqs plugin.

lucasbradstreet 2018-04-17T00:11:37.000072Z

prepare-batch allows you to get all of your requests together

lucasbradstreet 2018-04-17T00:12:26.000402Z

then write-batch allows you to initiate your requests, and return false if you’re not done, or true if you are done

lucasbradstreet 2018-04-17T00:12:56.000207Z

Generally I’d recommend returning true if you’ve started all of your requests, or false if you have only started some of them and you want to stay at the write-batch stage

lucasbradstreet 2018-04-17T00:13:24.000242Z

Then the additional missing piece is that you HAVE to ensure all of your requests have completed in the synced? call https://github.com/onyx-platform/onyx-amazon-sqs/blob/0.12.x/src/onyx/plugin/sqs_output.clj#L44

lucasbradstreet 2018-04-17T00:13:53.000277Z

The sync call is what allows a barrier to progress through, and if you have synced you are essentially signalling that you have completed everything between two barriers and it is safe to checkpoint.

lucasbradstreet 2018-04-17T00:16:04.000019Z

The idea is that you have two places you can backpressure (write-batch and synced?). write-batch and prepare-batch also allow you to yield and not progress to the next state, which allows you to give back the thread to the peer so that it can heartbeat if your request is long running. That way your peer doesn’t get timed out.

2018-04-17T00:32:08.000010Z

Ah OK

2018-04-17T00:33:52.000224Z

So if write-batch returns false, the task will yield execution back to the thread? So basically I can do something like the http plugin that tracks how many requests have been fired off and return true when that’s equal to the size of the batch? And if that’s the case I suppose synced would have similar logic I don’t think I need to do any work in prepare-batch right now, though

lucasbradstreet 2018-04-17T00:34:56.000090Z

Yes, that’s exactly right.

lucasbradstreet 2018-04-17T00:35:40.000224Z

You can decide whether you want to backpressure until the requests finish early in write-batch or just at the end with synced, depending on your needs.

lucasbradstreet 2018-04-17T00:36:59.000054Z

With write-batch you can also stage your “unfired” requests in an atom, and continue to fire them off from write-batch, returning false until they’re done. It’s probably safer than counting them.

2018-04-17T00:37:20.000106Z

Yeah that’s a fair point

lucasbradstreet 2018-04-17T00:40:00.000334Z

Is this writing to a particular DB/queue type product, or is it calling a web service? I’m just gathering info on what people are doing with the plugins.

2018-04-17T00:43:18.000008Z

It’s for invoking (or calling other methods on) AWS Lambdas. We had issues where tasks were failing to heartbeat due to long-running email requests that would error & timeout eventually (blocking on the call), which would cause retries and result in duplicate messages being sent. In this case we were also sending SMS messages in the same task, which would succeed, so we would get duplicated SMS messages

lucasbradstreet 2018-04-17T00:44:14.000270Z

Ah, cool. This is a good answer to that problem. It’s much better than just increasing the subscriber and publisher timeouts.

2018-04-17T00:45:38.000297Z

Cool! Yeah we were hoping it would be 🙂