Coder Social home page Coder Social logo

Run as a worker process about symfony-bundle HOT 2 CLOSED

cron avatar cron commented on August 11, 2024
Run as a worker process

from symfony-bundle.

Comments (2)

NoUseFreak avatar NoUseFreak commented on August 11, 2024

Hi @lokhman! Thanks for using and trusing this project :-).
At the moment it's not possible to run this in daemon mode. I would love to add this as I like the feature! Maybe there are already other projects allowing you to get this behaviour but it feels like something this project can provide.

I would suggest implementing a -d flag on cron:run to make it start in daemon mode.
As my schedule is really packed at the moment, feel free to implement it.
Maybe https://reactphp.org/event-loop/ is a good starting point to get this working.

Feel free to ask any questions you want answered. I'll try to get back to you quicker than I did just now.

from symfony-bundle.

lokhman avatar lokhman commented on August 11, 2024

Thank you, @NoUseFreak, for the reply!

As this feature was not available in the library and I needed a fast solution to embed one in the project, I wrote a very simple console script, which so far works very well:

#!/usr/bin/env php
<?php

use Symfony\Component\Process\Process;

umask(0000);
set_time_limit(0);

require __DIR__.'/../vendor/autoload.php';

$process = new Process(__DIR__.'/console cron:run');
$process->setTimeout(0);

while (true) {
    $now = microtime(true);
    usleep((60 - ($now % 60) + (int) $now - $now) * 1e6);

    if (!$process->isRunning()) {
        $process->start();
    }
}

This behaves like a synchronous crontab, which runs cron:run command exactly every minute (0 * * * *). Saying "synchronous" I mean that if a command gets executed for more than a minute, it will skip the next execution. In my project this will never happen, although making it asynchronous should not be a big problem.

I was also looking at event-loop library, but thought that probably for this kind of task utilising a full-featured event extension is a bit of an overkill, which will require an extra dependency. Component symfony/process has enough functionality to execute commands asynchronously, while making a simple queue should be a trivial task. What do you think? Is there anything I'm missing?

from symfony-bundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.