2017 © Pedro PelĂĄez
 

luya-module luya-module-scheduler

The LUYA Scheduler module.

image

boehsermoe/luya-module-scheduler

The LUYA Scheduler module.

  • Tuesday, June 5, 2018
  • by boehsermoe
  • Repository
  • 0 Watchers
  • 1 Stars
  • 27 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 4 Versions
  • 23 % Grown

The README.md

Scheduler Module

Installation

composer require boehsermoe/luya-module-scheduler:"~1.0.0", (*1)

In order to add the modules to your project go into the modules section of your config:, (*2)

return [
    'modules' => [
        // ...
    'scheduleradmin' => [
            'class' => 'luya\scheduler\admin\Module',
        ],
        'scheduler' => [
            'class' => 'luya\scheduler\frontend\Module',
        'accessToken' => '{token for web access}' // optional for webcron
        ],
        // ...
    ],
];

```shell ./vendor/bin/luya migrate ./vendor/bin/luya import, (*3)


Don`t forget to assign permission to user group for the scheduler module. ## Start jobs manuell via CLI Start all expired jobs manual: ```shell ./luya scheduler/run

Execute specified job:, (*4)

./luya scheduler/run/now {id/name of the job}

Trigger jobs by cron

Start all expired jobs every minute via cron:, (*5)

* * * * * ./luya scheduler/run

Trigger jobs alternativ

Via Webcron

Call the route https://{Host}/scheduler/run?token={Access token from config} to start expired jobs. You can use this url for webcrons like https://cron-job.org/de/ or https://uptimerobot.com/. Or any other webcron service., (*6)

Via yii application event

[
...
 'on afterRequest' => function() {
     if (!$this->isCli()) {
         Yii::$app->getModule('scheduler')->runExpiredJobsAsync();
     }
 },
...
]

CommandJob: Execute console commands

For example you can flush the cache every hour by add a new CommandJob (Scheduler -> CommandJobs -> Add) and insert "cache/flush-all" as command. The command is the route of the console command., (*7)

commandjob-screen, (*8)

Custom Jobs

You can also write your own jobs classes in the path "{appBasePath}/schedulers" or "{moduleBasePath}/schedulers". Every job have to inherite from BaseJob., (*9)

class ExampleJob extends \luya\scheduler\models\BaseJob
{
    public function run()
    {
        // Do your job.
    }
}

A job with a text field as option could look like this:, (*10)

class ExampleTextJob extends \luya\scheduler\models\BaseJob
{
    public $text;

    public function rules()
    {
        return array_merge(parent::rules(), [
            [['text'], 'required']
        ]);
    }

    public function extraFields()
    {
        return [
            'text'
        ];
    }

    public function ngrestExtraAttributeTypes()
    {
        return [
            'text' => 'text',
        ];
    }

    public function run()
    {
        // Do your job
    //
    // echo $this->text;
    }
}

More examples

For file backups: https://github.com/boehsermoe/luya-module-backup/blob/master/src/schedules/FileBackupJob.php, (*11)

For database backups: https://github.com/boehsermoe/luya-module-backup/blob/master/src/schedules/DatanbaseBackupJob.php, (*12)

The Versions

05/06 2018

dev-master

9999999-dev http://luya.io

The LUYA Scheduler module.

  Sources   Download

MIT

The Requires

 

php yii2 module yii backup luya

17/04 2018

1.0.2

1.0.2.0 http://luya.io

The LUYA Scheduler module.

  Sources   Download

MIT

The Requires

 

php yii2 module yii backup luya

17/04 2018

1.0.1

1.0.1.0 http://luya.io

The LUYA Scheduler module.

  Sources   Download

MIT

The Requires

 

php yii2 module yii backup luya

17/04 2018

1.0.0

1.0.0.0 http://luya.io

The LUYA Scheduler module.

  Sources   Download

MIT

The Requires

 

php yii2 module yii backup luya