sieppl / yii-job

4 stars 0 forks source link

Asynchronous jobs not works #3

Open samokspv opened 9 years ago

samokspv commented 9 years ago

config/console.php:

'components'=>array(
        'jobManager' => array(
            'class' => 'application.modules.job.components.JobManager',
            'jobs' => array(
                array(
                    'class' => 'MyJobCommand', //this is your own class that extends application.modules.job.models.Job
                    'crontab' => '* * * * *'
                ),
                array(
                    'class' => 'MyJob2Command', //this is your own class that extends application.modules.job.models.Job
                    'crontab' => '* * * * *'
                ),

My Jobs:

<?php
class MyJobCommand extends Job
{
    protected function _execute() {
        sleep(30);
        file_put_contents('job', 'job');
        return true;
    }
}
<?php
class MyJob2Command extends Job
{
    protected function _execute() {
        sleep(10);
        file_put_contents('job2', 'job2');
        return true;
    }
}

$crontab -e:

* * * * * cd $PROJECT_DIR && ./yiic job

One process in ps list instead of two:

$ps ax | grep yiic
18465 ?        Ss     0:00 /bin/sh -c cd $PROJECT_DIR && ./yiic job
18466 ?        S      0:00 php ./yiic job
sieppl commented 9 years ago

Please describe your problem. Note: The crontab definition inside the yiic config DOES NOT create crontab processes. We just use a crontab style to tell the job command how often the jobs should be executed.

Please call yiic job from console and check with logging if your jobs are executed.

samokspv commented 9 years ago

Thanks for answer!

Note: The crontab definition inside the yiic config DOES NOT create crontab processes. We just use a crontab style to tell the job command how often the jobs should be executed.

Yes, it is clear.

Fow example above i execute ./yiic job and all 2 jobs executed fine, but in ps list was one process instead of two, I expected that there will be two process or at least: 2nd job finished faster then 1st job, (asynchronous/parallel execution of jobs MyJobCommand and MyJob2Command).