Custom Scheduled Tasks

Hey @dan ,

I’m trying to write a custom task that writes entries to the Xibo schedule based on an external feed. I was able to figure out how to get a custom module working, but I can’t get the system to run my custom task.

  1. Can you explain what I need to do to get a custom task to actually run? Right now the Last Run is blank and the Last Duration is 0, as opposed to 0:00:00.
  2. Also, what is the proper method for writing to the schedule? Is there a model that can be accessed?

Thanks!

Hey,

Tasks use the CRON syntax for their schedules and have a flag to activate. If you’ve set both of those things, then there isn’t any reason they shouldn’t run. Is the next run date something sensible?

Your question regarding the schedule is a good one - it is counter intuitive, but I’d actually recommend having your task talk via the public API. Reason being, if the internal API changes (which it can do), you are insulated from that change.

I usually have a private function in my task that sets up the API using the wrapper library we’ve provided:

/** @var  XiboEntityProvider */
private $xibo;

/** Initialise the API */
private function initialiseApi()
{
    // Register a provider and entity provider to act as our API wrapper
    $provider = new \Xibo\OAuth2\Client\Provider\Xibo([
        'clientId' => $this->getOption('xibo-clientId', null),
        'clientSecret' => $this->getOption('xibo-clientSecret', null),
        'redirectUri' => '',
        'baseUrl' => $this->getOption('xibo-address', null)
    ]);

    $this->xibo = new \Xibo\OAuth2\Client\Provider\XiboEntityProvider($provider);

    $this->log->info('Connecting to ' . $provider->getBaseAccessTokenUrl([]));

    // Check connectivity
    $me = $this->xibo->getMe();

    $this->log->info('Connected as ' . $me->getId());
}

And I usually provide the API key/secret as options on the task, although you can hard code these.

You can then create a XiboSchedule object to create your schedules: https://github.com/xibosignage/oauth2-xibo-cms/blob/master/src/Entity/XiboSchedule.php#L13

Does that make sense?

Thanks for the help! I was going to write a task that would pull XML from an external source and then schedule events based on that feed, but since I was going to end up using the REST API anyway, it turned out that it was easier to just push events from the external server to Xibo.

1 Like

Makes a lot of sense to do it that way around!