Running asynchronously tasks from a Shell in Cakephp 2.0 - shell

I don't have a lot of experience in Cakephp 2.0, but I want to create a shell that will call more tasks.
The idea is that I don't want to add many cron jobs but I would like to have more tasks.
The main question is if the tasks from a Shell are called asynchronously or synchronously.
It would be great if they are called asynchronously, but if not, what other solutions might there be for my problem?
Thanks.
UPDATE 1
I have tested and it's very clear that tasks called in a Shell are called and executed synchronously. How can I change this? I want to start more task in the same time from the same Shell.

The Queue plugin does pretty much exactly what you want.

Related

Is it right pattern of using Spring batch if one task that is launched through SCDF API call will launch other task through SCDF API calls?

I have a requirement to have a schedule batch that will identify what are the batches I need to restart or re-submit(as new job instance). Schedule batch will identify and call SCDF API to launch tasks. Is it really good design pattern to have a such batch ?
I can implement the above require pattern but is is good practice or anyone can suggest what is alternate way of doing it.
I see nothing wrong in implementing that requirement with Spring Batch (it would be a single step job with a simple tasklet). The question you should be asking is that do you really need a Spring Batch job for that? What would you gain from using Spring Batch? Most interesting features won't be used for that job (restartability, fault-tolerance, transaction management, etc), so the benefit/cost ratio is low IMO.
I have seen folks putting similar logic (db query + rest call) in a shell script scheduled with crontab. And I see nothing wrong with this approach neither.
So it really depends on how you want to implement that requirement.

Spring Boot run multiple Task concurrently

I have a question regarding Spring Boot. My web application has different Users. For each User, I need to run several Tasks (e.g import/export CSV, run rest request process it and answer it, ...).
So let's say we have about 4 tasks per user. and now when I have 100 users I would have 400 tasks.
Now my question is how can I handle such an amount of task? The task should be scheduled with a cron expression and need to run parallel / concurrent so that no user has a disadvantage.
The Main Question is I really don't know how to make all this task run concurrently so that the tasks run parallel. How do I make that what SpringBoot-Things do I need to use (e.g a special Scheduler?).
Is it even possible to handle such amount of task running parallel/concurrently?
Thank you for your help :)

Using ruby and sinatra how can I schedule a script to run (at an unpredictable time) in the future?

I am designing a reminder type app. Somebody enters into a form, for example, "call me at such and such a time on such and such a day in the future to remind me of something".
This is put into a postgres database. Obviously lots of people (hopefully) will be doing this and scheduling different things at different times in the future.
So, my question is how can ensure that my app checks the database for things it has to do at the right time? Can I:
a) should I, when the entry is made, create an automated script to execute at the time necessary to perform the reminder function? If so, how?
b) get my app to check the database every minute, again if so how? This would seem a huge waste of resources.
Sorry I cannot provide any code for this but I have no idea where to begin. all help gratefully received.
Thank you!
You might wanna use a background job framework like Sidekiq. Sidekiq supports scheduled jobs like this:
Notifier.perform_at(a_time_object, message_to_send)
It seems like Sidekiq also works with Sinatra.
For that particular task I prefer whenever https://github.com/javan/whenever

Scheduled tasks with multiple servers - single point of responsibility

We have a Spring + JPA web application.
We use two tomcat servers that run both application and uses the same DB.
One of our application requirmemnt is to preform cron \ scheduled tasks.
After a short research we found that spring framework delivers a very straight forward solution to cron jobs,
(Annotation based solution)
However since both tomcats running the same webapp - if we will use this spring's solution we will create a very problematic scenario where 2 crons are running at the same time (each on a different tomcat)
Is there any way to solve this issue? maybe this alternative is not good for our purpose?
thanks!
As a general rule, you're going to want to save a setting to indicate that a job is running. Similar to how "Spring Batch" does the trick, you might want to create a table in your database simply for storing a job execution. You can choose to implement this however you'd like, but ultimately, your scheduled tasks should check the database to see if an identical task is already running, and if not, proceed with the task execution. Once the task has completed, update the database appropriately so that a future execution will be able to proceed.
#kungfuters solution is certainly a better end goal, but as a simple first implementation, you could use a property to enable/disable the tasks, and only have the tasks run on one of the servers.

How do I test DelayedJob with Cucumber?

We use DelayedJob to run some of our long running processes and would like to test with Cucumber/Webrat.
Currently, we are calling Delayed::Job.work_off in a Ruby thread to get work done in the background, but are looking for a more robust solution
What is the best approach for this?
Thanks.
The main problem I see with the Delayed:Job.work_off approach is that you are making explicit in your Cucumber scenarios something that belongs to the internals of your system. Mixing both concerns is against the spirit of functional testing:
When I click some link # Some operation is launched in the background
And Jobs are dispatched # Delayed:Job.work_off invoked here
Then I should see the results...
Another problem is that you populate your Cucumber scenarios with repetitive steps for dispatching jobs when needed.
The approach I am currently using is launching delayed_job in the background while cucumber scenarios are being executed. You can check the Cucumber hooks I am using in that link.

Resources