2017 © Pedro Peláez
 

library mashtru

A framework-agnostic php library usefull to manage scheduled tasks on shared webhosting or not

image

vikkio88/mashtru

A framework-agnostic php library usefull to manage scheduled tasks on shared webhosting or not

  • Wednesday, March 8, 2017
  • by vikkio88
  • Repository
  • 1 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

mashtru

Build Status, (*1)

mashtru will manage scheduled task on shared hosting (and everywhere else really), (*2)

Problem

Shared php web hosting, usually give you a limited number of scheduled task script (from 1 to 5), and if you need you app to perform some async cron jobs, and you dont want to forget about single responsibility principle, you will just need to mashtru., (*3)

Hook script

Set the only scheduled task to be the hook.php script, which will be something like this, (*4)

<?php
require '../vendor/autoload.php';

use Mashtru\JobManager;
use Mashtru\Libs\Helpers\DBConfig;
use Mashtru\Libs\Helpers\RunnerConfig;

$jobs = new JobManager(
    new DBConfig(
        'localhost',
        'mashtru',
        'root',
        'root'
    ),
    new RunnerConfig(
        [
            'App\Scripts\\'
        ]
    )
);

$jobs->fire();

and imagine to have a job si defined in the file DosomeStuff.php, (*5)

<?php

namespace App\Scripts;

use Mashtru\Libs\Interfaces\Job;

class DoSomeStuff implements Job
{

    public function fire(array $parameters = [])
    {

        echo "I do some cron stuff!";
        //SOME STUFF


        //RETURN AN INT
        return 0;
    }

    public function getName()
    {
        return 'DoSomeStuff';
    }
}

The fire method of this class will be called how many times you defined it in the Job configuration., (*6)

Configure Jobs

mashtru uses a single table called mashtru_jobs, there the structure is as follows, (*7)

CREATE TABLE mashtru_jobs(
    id SMALLINT NOT NULL AUTO_INCREMENT,
    name VARCHAR(255),
    class_name VARCHAR(255) DEFAULT NULL,
    args TEXT DEFAULT NULL,
    delta_minutes INT DEFAULT NULL,
    active BOOL DEFAULT 1,
    fire_time TIMESTAMP NULL DEFAULT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW(),
    created_at TIMESTAMP NOT NULL,
    PRIMARY KEY(id),
    INDEX `name` (`name`)
);
column description
id the incremental id for the job
name the job name (used to identify a job)
args a text field that will be passed into the fire function (I would cast it with json_decode as config param)
class_name the name of the class which fire() method will be called
delta_minutes the difference on minutes of the iteration for this job (it will be executed every delta_minutes minutes)
priority a TINYINT value which jobs will be order by with DESC direction (0 by default) (from -128 to 127)
active whether or not the job is active
fire_time calculated column that will tell mashtru whether the job is ready to be fired or not

The class JobManager offers utility to install/uninstall/add/delete/update/get jobs from this table. The implementeation of those action is delegated to the library user. I will use it within a protected rest-api i.e. so I would be able to set manage the jobs using a rest-api., (*8)

Collabs

This is a silly lib that I wrote for me, every help of feedback is well appreciated., (*9)

ToDos

  • Make table_name configurable
  • Replace delta_minutes with cronjob-like configuration

The Versions

08/03 2017

dev-master

9999999-dev

A framework-agnostic php library usefull to manage scheduled tasks on shared webhosting or not

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincenzo Ciaccio

job vikkio88 scheduled-task php-scheduler cronjob-php

04/03 2017

v1.0.1

1.0.1.0

A framework-agnostic php library usefull to manage scheduled tasks on shared webhosting or not

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincenzo Ciaccio

job vikkio88 scheduled-task php-scheduler cronjob-php

11/02 2017

v1.0

1.0.0.0

A framework-agnostic php library usefull to manage scheduled tasks on shared webhosting or not

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincenzo Ciaccio

job vikkio88 scheduled-task php-scheduler cronjob-php

11/02 2017

v0.1

0.1.0.0

A framework-agnostic php library usefull to manage scheduled tasks on shared webhosting or not

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vincenzo Ciaccio

job vikkio88 scheduled-task php-scheduler cronjob-php