How to wait for tasks to be completed by GPars Agent class? - gpars

Currently I am using GPars Agent class to process typical shopping cart scenario. I have a situation where I need to wait for addtocart, minicart tasks to complete before viewcart task returns response. The webservice call returns viewcart before returning addtocart/minicart. How do I let Agent class know to process the viewcart after other tasks are completed?

Agents always process submitted tasks sequentially. So if you submit the viewcart task last, it will be processed last.
You may call agent.await() of agent.val to block the caller until all so-far-submitted tasks have been completed.

Vaclav Pech,
Thank you much. Appreciate your help. I have handled this scenario adding a counter before(increment counter) and after(decrement counter) the service and waiting for the items to be processed in the View cart and redirect them to viewcart page. Just wanted to add my answer to this thread.

Related

How to obtain the return value from a function enqueued in rq?

From the documentation of redis queue https://python-rq.org/docs, I came to know that the worker can return results only after a certain time and till then return None.
Is there any way to find out that the worker execution is complete (not with time.sleep() pls.) ?
In my case what is happening is the worker keeps running and the data displayed on the UI is None as the control moves to my rendering of UI code as soon as worker is assigned the task and doesnot wait to complete the execution ?
Pls. help me.
I know it's been a year, but if someone else needs it:
that depends on your needs - I'd use supervisor, do you can easily see updated output of each running worker/process, either with the output file, or in the browser, with the inet_http_server section
if you want something done, after the current job has finished - just chain jobs to the queue.
you only need to specify the job in the "depends_on" parameter.docs

Is it safe to call BackgroundJob.Enqueue from inside a RecurringJob?

I have a RecurringJob that receives some rows from a database and I want to send an email for each row. Is it safe to call BackgroundJob.Enqueue within the recurring job handler for each row to send an email?
My aim is to keep the work in the recuring job to a minimum.
It's a bit late to answer this but yes, you can call BackgroundJon.Enqueue() from within the recurring job. We use MongoDB and since it is thread safe, we have one job creating other jobs that run both serially and parallel.
Purpose of background jobs is to perform a task whether you start from an API call, recurring job or the background job itself.

How to run threads concurrently in jmeter

Hi i have created a thread group which contains 10 transaction controller, each control has multiple number of HTTP request samplers.
Now to identify the bottleneck as per the requirement, each transaction control has to run one after another.
For ex: 30 threads- Register and login. send reports and logout is the scenario.
so, For each action i have created 1 transaction controller which contains required http sampler request. First i need to run register for 30 users. after getting the response for all 30 users then only login transaction controller should run. and so on.. one by one.
I tried creating multiple thread groups but i am fetching security tokens in each group. So if i create multiple thread group i cant call variable values of one thread group in another.
So pls if anyone know the solution help me out, i am a beginner to jmeter...
This can be achieved using only 'Synchronizing Timer' element of the JMeter. Please find below the brief description of this element:
Synchronizing Timer: This element is used when you intentionally want to pause the users/threads at a specific step until the count of user mentioned in this element is reached
You can create your script in following structure:
Transaction Controller for Register requests
HTTP Register Request1
HTTP Register Request2
Transaction Controller for Login requests
HTTP Register Login1
Synchronizing Timer [Set the 'Number of Simulated Users to Group by' to 30 and Timeout based on your requirement [Recommended value to set is '300000' i.e 5 minutes]. Do not set Timeout to '0' otherwise your test will remain in running state forever if any of the user gets failed in previous step]
HTTP Register Login2
HTTP Register Login3
Note: In above example, you can see I have added synchronizing timer as a child of first HTTP sampler request of under Login transaction controller.
When the test reach at 'HTTP Register Login1' then before sending this request, it will perform the synchronizing timer and wait for all the users to complete the register action.
For beginners, the following blog posts of RedLine13 are very useful to jump start on JMeter:
https://www.redline13.com/blog/kb/
Also, the response time will definitely increase when you use the synchronizing timer because this timer will pause the test until all user reached the step and then perform the login operation. As all 30 users will perform the login action at the same time so the response time will go high as compared to the case when some users are doing registration and others doing login.
Kindly let me know if you have any questions.
If you want "login" transaction to be kicked off only when all 30 users completed "register" transaction you need to:
Add Test Action sampler between "register" and "login" transaction controllers
Add a Synchronizing Timer as a child of the Test Action sampler and set Number of Simultaneous Users to Group by to 30
This way Test Action sampler will act as a "rendezvous point" so all 30 threads will "meet" there, this way you will get confidence that all 30 threads completed registration prior to starting logging in.
Example test plan:

Cancelling sendAsynchronous request

I am using sendAsynchronous request to receive data from multiple request at same time. It works great, i am able to load all the data. Even it is faster. But i want to cancel my request if the user cancels the request. so i have created a NSThread and using that thread i have created asynchronous request. When user clicks cancel button i just cancelled the thread.
But even after cancelling the thread the data is still getting loaded. So i want to stop those requests completely from loading data.
Even i used this,
[NSObject cancelPreviousPerformRequestsWithTarget:(id) selector:(selector) object:(id)]
but it doesn't work. Any help or suggestion will be appreciated.
Thanks in advance.
According to the documentation the NSUrlConnection class has it's own cancel method.
Note: Why are you using sendAsynchronousRequest in a own thread? The completion-handler will be executed when the request returns. While the request tries to reach the server and get an answer the main-thread shouldn't be blocked. I suggest to use either a synchronous request in a background thread or an asynchronous request in your main thread.
Also be aware, that your thread doesn't terminate just by calling [NSThread cancel]

Handling long running webrequest

I have a web request that can take 30-90 seconds to complete in some cases(most of the time it completed in 2-3). Currently, the software looks like it has hung if the request takes this long.
I was thinking that I could use background worker to process the webrequest in a separate thread. However, The software must wait on the request to process before continuing. I know how to setup the background worker. What I am unsure about is how to handle waiting on the request to process.
Do I need to create a timer to check for the results until the request times out or is processed?
I wouldn't use a timer. Rather, when the web request completes on the worker thread, use a call to the Invoke method on a control in the UI to update the UI with the result (or send some sort of notification).