I have an ActiveJob which is to load a piece of data from external system from HTTP. When that work is done, I want to do another task which does postprocessing and then submits the data to a different external system.
I do not want the first job to know about other jobs, because
Similarly, if I fail to load the data - maybe the user be notified, then maybe we will have to Try, maybe we log in it and throw your hands - still it is different depending on it It is possible. There is no need to include the explanation of the exception, and the logic for the job, which connects with other systems to handle it.
In Java (where I have most experience), I can use some like guava to add success and failure callback after the fact:
MyDataLoader loader = New MyDataLoader (someDataSource) ListenableFuture & lt; Data & gt; Future = executor submit (loader); Futures.ADClack (Future, New Future Callback () {Public Results at Zero (Data Result) {Process Data (Results);} Public Zero (Throwable) {handleFailure (t);} at zero; });
However active job does not provide this type of external callback mechanism - the best I can do in "active work default", after_perform
and rescue_from
are only for calls from within the job class and after_peform
is not to distinguish between success and failure.
So the best I have been able to come up with (and I am not claiming this very good) is to pass some commodity into the job's display
method , As follows:
class MyRecordLoader & lt; ActiveJob :: Base # The cost of the load data (hopefully on the background queue) and #define the result, or any exception to the appropriate Lambda near # # @PRAMData_Source [String] url # @PRAM to load data from ONSUVE [- & gt; (String)] A lambda which will be recorded # data, if it has been successfully loaded # @Only on_failure [-> (Exception)] A lambda that will be passed to any # exception, if a DRF display (data_source, on_suse, on_fileer) starts, then result = load_data_expensively_from data_source on_success.call (result) rescue = & gt; Exception on_failure.call (end)
(Side note: I do not know what yardoc syntax is to declare lambda as a parameter. Is it true, Or,
MyRecordLoader.perform_later (some_data_source, method (: process_data), method (: handle_failure))
< P> Code>
This is not the least awesome on the calling side, but it seems to be clunky, and I can not help but suspect it for There is a similar pattern I just do not search And I am worried that, as a Ruby / Rail novice, I am only bending to active Job, which was not meant to be done in the first place. All the active examples are getting me 'fire and mistake' - asynchronous form The result of "returning" does not appear in the case of an ActiveJob use.
In addition to this, it is not clear to me that
What's the Ruby Way?
Update: As the dre-hh, ActiveJob did not get the right tool here. It was also unbelievable, and more and more for the situation. I switch in return, which improves the case of use, and the work that is mostly IO-bound, is also fast enough on MRI.
ActiveWeb does not have an async library like a future or promise.
This is the only interface to work in the background. The current thread / process does not get any results from this operation.
For example, when the Sidekick is used as the Active Job Queue, it will serialize the parameters of the display method in the Radius Store. Another demon process running in the context of your Rail app will be looking at the queue queue and will prompt your workers to start with serialized data.
Therefore the callback pass may be fine, however, why should they take it as another category. On passing the callback, it will understand whether they are moving (turning on different invitations) However, as you have implemented them on the calling class, consider moving those methods to your job worker class only. Please.
No comments:
Post a Comment