ScheduledExecutorService stops a scheduled runnable task and then reruns fine after some time - dropwizard

I have a DropWizard application where we are using Managed Objects(https://www.dropwizard.io/0.6.2/manual/core.html#managed-objects) capability provided by DropWizard. We have used ScheduledExecutorService to scheduled a Runnable from the class which implements Manage which runs very much fine in the time intervals specified(90 mins) but abruptly stops after some runs(there is no particular number to it) and then after some time gets re-triggered again and starts functioning normally.
I have seen that there are no exceptions happening in between so that the run would stop and not do the runnable task that it is supposed to do.
Has anyone encountered this issue earlier and can help with the issue.
Here is how we are scheduling it.
scheduledExecutorService.scheduleAtFixedRate(runnableTask, 1, 90, TimeUnit.MINUTES);

Related

How to test expected delay time on page element (fixed wait, debounce) with Playwright

How to test implemented fixed delay on webpage with Playwright (exactly: debounce)?
I have simple scenario. User, after entering input need to wait fixed time for response i.e. 1000ms.
How to test that exact wait with Plawright?
Looked at https://github.com/microsoft/playwright/issues/4405 but I wonder if there is more elegant way to do this?
Well usually there is a better way than to hardcode a waiting time.
Wait for certain API calls
Wait for network idle (= wait for started calls to finish)
Wait for an event
However there are times when hardcoding is inevitable. What I've used is page.waitForTimeout()
Wait for 2 seconds:
await page.waitForTimeout(2000);
Official docs: https://playwright.dev/docs/api/class-page#page-wait-for-timeout
"Waits for the given timeout in milliseconds.
Note that page.waitForTimeout() should only be used for debugging.
Tests using the timer in production are going to be flaky. Use signals
such as network events, selectors becoming visible and others
instead."

Page freezes when running process in background with suckerpunch

i try to start a process in the background which executes some code. When i start the process, my app freezes until the background task is done. Iam using SuckerPunch to work around exactly this freezing, however the app still waits for the process to end. Do i have the wrong expectations ? How can i solve it ?
app/controller/mycontroller:
MyJob.perform_async(data_array)
app/jobs/myjob:
class MyClass
include SuckerPunch::Job
workers 1
def perform(data)
my code which takes around 20sec to execute
end
end

how to schedule after the current thread has terminated?

I am creating a user defined thread library. I use Round-Robin scheduling algorithm and use the context switching method. But, I am unable to know what to do when a thread finishes its execution before the allotted time slot. The program is getting terminated. I actually want to reschedule all the threads, by calling the schedule function when the current thread gets terminated.
I found two ways to overcome this problem.
By calling explicitly thread_exit function at the end of the function that is being executed by the current thread.
By changing the stack contents such that the thread_exit function gets executed after the current function gets terminated.
But I am unable to find how to apply these solutions....
Anybody out there... plz help me...
It sounds like you have a bit of a design flaw. If I'm understanding you correctly, you're trying to implement a solution where you have threads that can be allocated to perform some task and after the task is complete, the thread goes idle waiting for the next task.
If that's true, I think I would design something like a daemon process or service that manages a queue for tasks coming in, a pool of threads responsible for executing the tasks with a controller that listens for new tasks.

Why a thread is aborted in ASP.NET MVC (again)?

Here is what I do in a controller action:
create and start a new Thread that does a relatively long processing task (~30 seconds on average, but might be several minutes)
immediately return the page response so the user knows processing has started (trivially, a Json with a task ID for polling purposes).
At some random point, ThreadAbortException is thrown, so the async task does not complete. The exception is not thrown every time, it just happens randomly roughly 25% of the times.
Points to note:
I'm not calling Response.End or Response.Redirect - there isn't even a request running when the exception is thrown
I tried using ThreadPool and I got the same behavior
I know running threads in ASP.NET has several caveats but I don't care right now
Any suggestion?
The problem is you shouldn't do it this way. If you need a task to run for a long period of time in the background ASP.Net should either spawn a process to handle it or add the work item to a queue for a Windows Service to handle.
Does this help since you want to fire and forget.
"Delegates provide a method called BeginInvoke that allows us to call the delegate asychronously."
http://hackingon.net/post/Asynchronous-fire-and-forget-method-calls-in-NET.aspx
How about using an Asynchronous controller?
The problem was that the app was being recycled. I perfectly know that when that happens, all threads are aborted, I didn't expect the application to recycle. The reason is that the async process used changed temp files stored in the app root, and that caused a recycle.
I feel dumb.

Backgroundrb scheduled task ending

I have a backroundrb scheduled task that takes quite a long time to run. However it seems that the process is ending after only 2.5 minutes.
My background.yml file:
:schedules:
:named_worker:
:task_name:
:trigger_args: 0 0 12 * * * *
:data: input_data
I have zero activity on the server when the process is running. (Meaning I am the only one on the server watching the log files do their thing until the process suddenly stops.)
Any ideas?
There's not much information here that allows us to get to the bottom of the problem.
Because backgroundrb operates in the background, it can be quite hard to monitor/debug.
Here are some ideas I use:
Write a unit test to test the worker code itself and make sure there are no problems there
Put "puts" statements at multiple points in the code so you can at least see some responses while the worker is running.
Wrap the entire worker in a begin..rescue..end block so that you can catch any errors that might be occurring and cutting the process short.
Thanks Andrew. Those debugging tips helped. Especially the begin..rescue..end block.
It was still a pain to debug though. In the end it wasn't BackgroundRB cutting short after 2.5 minutes. There was a network connection being made that wasn't being closed properly. Once that was found and closed, everything works great.

Resources