The docs only mention an abort parameter in the return object for custom functions. Are there any other parameters or callbacks too? What if I want to do some task after the custom function such as process is done?
There are not other methods to return in a custom process method. If you want to run other functions on the file you can do all of that in the process method and accumulate the progress. You could for example upload to multiple locations and only call load when the final upload completes. An alternative is to run additional functionality in the onprocess callback.
Related
I'm trying to perform a asynchronous task that fills an array of object from a REST web service call.
I'm writing the code inside the handle() method inside the job's class.
The controller should be able to retrieve an object from that array at any time.
This task is supposed to run continuously so that whenever I want to retrieve an object, my array still contains data.
My question is how to make a job that executes permanently and how can I retrieve the data from my controller?
Thanks in advance
You need to store (cache) array from job somewhere (db, redis, files) after every operation.
Then retrieve "fresh" array in controller from storage.
If objects in array are similar, you can create model and use standard laravel capabilities.
To run permanent task you can use this console command:
nohup php artisan {command_name} &
I'm using gin-gonic as HTTP handler. I want to prerender some graphical resources after my users make POST request. For this, I put a middleware that assign a function (with a timer inside) to a map[string]func() and call this function directly after assignation.
The problem is, when the user make two subsequent request, the function is called twice.
Is there any way to clear function ref and/or his currently running call like a clearInterval or clearTimeout in Javascript ?
Thanks
No; whatever function you've scheduled to run as a goroutine needs to either return or call runtime.Goexit.
If you're looking for a way to build cancellation into your worker, Go provides a primitive to handle that, which is already part of any HTTP request - contexts. Check out these articles from the Go blog:
Concurrency Patterns: Context
Pipelines and cancellation
I suppose your rendering function is calling into a library, so you don't have control over the code where the bulk of the time is spent. If you do have such control, just pass a channel into the goroutine, periodically check if the channel is closed, and just return from the goroutine if that happens.
But actually I would recommend a different, and simpler, solution: keep track (in a map) of the file names (or hashes) of the files that are currently being processed, and check that map before launching a second one.
I am facing trouble to call or fetch third party API for wit.ai.
How can i make AJAX call to fetch "weather" information and bind it to converse method.
In image context - wit.ai story fetchWeather(context) method. How to connect with ajax call to specific method for weather output.
FetchWeather(context)
so in NodeJs you can use callbacks or Promises to chain you're petitions.
Wit.ai has actions defined by yourself, each time Wit.ai send a messages, it calls the send action, but if you defined an action in your story, then all processes should be done inside that specific action (because it is execute before send action)
In the image above you can see my action named getFullName, inside there I chain promises to query the user name and then build the fullNameGreeting to insert in my context.
If you have any question, you should read the wit.ai tutorial and download the an implement version for Node or Python. https://wit.ai/docs/quickstart
Use mvvmcross for Xamarin.Android. Why MvxCachingFragmentCompatActivity call ExecutePendingTransactions in ShowFragment method manually? What actions done with this call? As I see, it can takes about second for several devices while navigation.
Thanks
It is basically necessary, if the next actions rely on the handling of the commit() before doing any other action.
For MVVMCross especially:
OnFragmentChanging(fragInfo, ft);
ft.Commit();
SupportFragmentManager.ExecutePendingTransactions();
OnFragmentChanged(fragInfo);
The OnFragmentChanged-Event should obviously only be called if the changes got applied. Just to take one of the code snippets out of MvxCachingFragmentCompatActivity.
From the API documentation.
After a FragmentTransaction is committed with
FragmentTransaction.commit(), it is scheduled to be executed
asynchronously on the process's main thread. If you want to
immediately executing any such pending operations, you can call this
function (only from the main thread) to do so. Note that all callbacks
and other related behavior will be done from within this call, so be
careful about where this is called from.
I have an object that is updated from a polling loop on a thread. This object fires particular events when data changes, etc.
I'm trying to use this object in conjunction with a windows form, where I create event handlers on the form to update the UI. Of course, this causes cross-thread operation exceptions if I try to manipulate the UI directly in these handlers.
I can get it to work by going through the standard procedure of checking InvokeRequired, using a delegate, blah blah blah. But I want to publish this object as a library, and I don't want end-users to have to worry about all that.
I want my object to somehow take care of synchronizing those event callbacks with the form so that end-users can manipulate the UI elements in those handlers worry-free.
Is there a way to do this??
If your object is always related to a single form, there is a simple trick indeed. The important fact here is, that you instanciate your object from the thread you like to affect the form later.
The trick is to instanciate a simple Control (new Control()) in your object in the constructor. When you perform logic on your form, use the Invoke/BeginInvoke methods on this simple control, to dispatch the action to the correct calling thread. So you have the dispatching logic directly in your object and there is no need for other users of your object to take care about this.