Creating a Custom Task

Hi all,

I am trying to create a custom task and change a setting on the database.
I am able create task and link to a php and run it but it doesn’t work.

I would like to use the TaskTrait from other tasks but I am not sure if it is possible with Xibo\Custom namespace.

Hey there,

We would need a bit more details on what you want to achieve, what you have and what exactly does not work please.

CMS version you have would be helpful as well.

Yes, you can use TaskTrait in your custom task, in fact, you most likely want to use it :slight_smile: .

If you look at the example here - Tasks - Extend Xibo | Xibo Open Source Digital Signage

You need to create the .task file as explained in the link.
Then create the task file itself, which if we follow the example from docs, at the very least needs this as base

<?php


namespace Xibo\Custom;


use Xibo\XTR\TaskInterface;
use Xibo\XTR\TaskTrait;

class CustomTask implements TaskInterface
{
    use TaskTrait;

    public function run()
    {
        // TODO: Implement run() method.
    }

    public function setFactories($container)
    {
        // TODO: Implement setFactories() method.
    }

}

You can have a look at one of the existing tasks to see how the workflow should work.

Once you’re happy you can go to Task page in your CMS, click add Task and select your custom task from the dropdown, specify cron schedule and options if needed.

Hi Peter,

Thank you for the answer.

I have tried on last few versions of cms (3.0.3 and 2.3.11).
I have a very basic task for now as shown below.

<?php

namespace Xibo\Custom;

use Xibo\XTR\TaskInterface;
use Xibo\XTR\TaskTrait;

class CustomTask implements TaskInterface
{
    use TaskTrait;

    public function run()
    {
        $this->runMessage = "test" . PHP_EOL . PHP_EOL;
        $this->log->debug("test");
    }
}
The Xibo Community site uses cookies. What are cookies?