How to create a cron task in Symfony2 - symfony

I have a little question, how create a simple cron task who call some service action in Symfony, who could be executed automatically each night ?

Symfony2 does not manage cron tasks, simply because this is system level. That being said, you can create a command and register it as a cron task.

You can use CommandSchedulerBundle

You can now use TaskScheduleBundle to make your cron jobs within symfony.

Related

Scheduling hangfire jobs in a different project to where they are executed

I have 2 .net core web projects.
One of them is called ScheduledJobs and it uses Hangfire with the dashboard to both schedule and process jobs.
The other is called ClientWebsite and it schedules the jobs only - but I dont want them executing here!
ScheduledJobs works fine, if I schedule anything from there it picks them up and processes them.
But since I need to be able to schedule jobs from clientWebsite too, I have to have the following settings in startup:
services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"));
services.AddHangfireServer();
If I dont call services.AddHangfireServer it wont even let me schedule them.
But if I add it, then it processes them too which I dont want !
Please help! Thanks
You shouldn't need to register the hangfire service at all in the second project in this way.
If you want to purely queue jobs from it you can use the GlobalConfiguration to set up which database it should point at similar to
GlobalConfiguration.Configuration.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"));
Once you have done this you can register a BackgroundJobClient similar to this (this is taken from an autofac example so depending on your DI it wont be exactly the same as the line below)
builder.RegisterType<BackgroundJobClient>().As<IBackgroundJobClient>();
What this then allows you to do is resolve and enqueue jobs using the IBackgroundJobClient in your application without setting up a hangfire server at all.
In your classes where you want to enqueue jobs from you can then simple resolve an instance of IBackgroundJobClient and make use of the Enqueue method such as
_myClient.Enqueue<MyJobClass>(x => x.APublicMethodOnMyJobClass());
Details on the backgroundjobclient can be found here - BackgroundJobClient

Modify the task schedule in Airflow

I want to modify the schedule of a task I created in a dags/ folder through the airflow UI. I can't find a way to modify the schedule through the UI. Can it be done or we can get it done only by modifying the python script ?
The only way to change it is through the code. As it's part of the DAG definition (like tasks and dependencies), it appears to be difficult to be able to change it through the web interface.

How to dynamically delete rows from table after time passes?

I know that i can do that with CRON but there are a lot of issues with these method. I have a Entity "Events" and when $eventDate <= Date (NOW) it will be deleted dynamically. I'm using PHP Framework Symfony2.
Why don't you want to use cron? Another approach is using queues that allow to use delayed messages (something like Beanstalkd, it has a lot of bundles for Symfony) -- but obviously it's more complicated than cron.
What issues are with a cron? You can create a symfony command that do what you want and call it from a event listener on the request or from a cron.
You can make a symfony command that delete the Event when $eventDate <= Date (NOW) and you can add a cron to run the command every X time

Symfony2 background task

I would create a background task that loops continuously with Symfony2
I want to know how to do this
protected function execute(){
while (true) {
sleep(60);
//------------ do some think
}}
As far as I know, PHP doesn't have threading, so you won't be able to run that in parallel with your Symfony application.
Instead, create a cron job which executes that code via CLI.
Here's a pretty straight-forward intro to cron jobs.
If you're on a Windows server, set up a scheduled task. See How to run a PHP file in a scheduled task (Windows Task Scheduler).

several hook_cron for one module, drupal 6

does anybody know is it possible (drupal 6) to create several tasks which should run by crontab? I've created hook mymodule_cron but I need one more. Is it possible to create something like mymodule_another_task_cron?
Thanks
Why don't you add another task in your existing hook_cron? You can call whatever functions you want from one hook_cron.
I can highly recommend the Elysia Cron module
Elysia Cron extends Drupal standard cron, allowing a fine grain control over each task and several ways to add custom cron jobs to your site.
As a module developer the method you'll be most interested in is implementing hook_cronapi() to register jobs that can be scheduled individually through the Elysia cron admin settings.
There's also Ultimate Cron, but I can't vouch for that one as I've never used it.

Resources