mn8 Language Reference | Index    

Cron

SUMMARY: NO ATTRIBUTES  ELEMENTS SUMMARY  NO CONSTRUCTORS  NO OPERATORS  METHODS SUMMARYDETAIL: NO ATTRIBUTES  ELEMENT DETAILS  NO CONSTRUCTORS  NO OPERATORS  METHOD DETAILS

Description

With this concept can you create a crontab and handle the Scheduler to schedule your jobs. Into the crontab can you add Unix like crons. The cron have the following elements: min, hour, dayOfMonth, month, dayOfWeek. If you want to use a days of month put "*" in the place of dayOfWeek, and you want to use days of week put "*" in the place of dayOfMonth.

A structure of one cron element can be:

The values of elements:

Usage

      # The cron is Singleton, you have only one instance on your terminal
      $y=Cron.getInstance

      # Every Monday on 0.10, 6.10, 12.10, 18.10 will execute the "Google ..." script
      Cron.addTask("10 0-23/6 * * 1", "Google rsearch Antal Attila atech")

      # Every 20th day of month on 14.30  will execute the "Google ..." script
      # and assigns the returned task id to $t (is Integer)
      $t = Cron.addTask("30 14 20 * *", "Google rsearch Gnome 2.0  distribution")

      # or if using the same cron you want to execute the method 
      # onlytest from Test concept with parameter "Hello World!"
      $ser typeof Series
      $ser.add("Hello World!")
      Cron.addTask("30 14 20 * *", "Test.onlytest", $ser)

      # looking after my cron tasks
      print $y.toXML

      # getting the tasks into the series
      $tasks = Cron.getTasks

      # Ugly task with id=1 I remove it
      Cron.removeTask(1)

      # How many tasks I have?
      print "" + Cron.getTasks@length

      # Be happy I starting the scheduler
      Cron.start

      # The system is hanging up and holds the scheduler to work
      System.pause(0)

      # Is something working bad or need to shut down the scheduler
      Cron.stop

Version: 0.1
Authors:Antal Attila ()
Location:
Inherits: Concept

Element List

 task TYPEOF Series LABEL "task"
top

Method List

static IntegeraddTask (String $timeString, String $task)
static IntegeraddTask (String $timeString, String $task, Series $ser)
static CrongetInstance
static SeriesgetTasks
static removeTask (Integer $taskId)
static start
static stop
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Element Info

task

Label:task
Type:Series
Is Static:false
Is Hidden:false
Is Multi:false
Show Empty:true

Task element to hold informations with its attributes

top

Detailed Method Info

static addTask (String $timeString, String $task)
Parameters:
$timeString :Cron string
$task :Execution string in order by ConceptName followed by it self attributes
Returns: Integer
Exceptions:
addTriggerException :
(Error)
If unable to add trigger to the Cron concept.
cronStringException :
(Error)
If the cron String isn't valid.

Adding task into your tasks.

    Cron.addTask("10 0-23/6 * * 1", "Google rsearch regexp syntax flags")
    This will execute the "Google rsearch ..." command every Monday on 0.10, 6.10, 12.10, 18.10
    

top
static addTask (String $timeString, String $task, Series $ser)
Parameters:
$timeString :Cron string
$task :Execution string like an mn8 static method call, Concept.method
$ser :A series for method parameters
Returns: Integer
Exceptions:
addTriggerException :
(Error)
If unable to add trigger to the Cron concept.
cronStringException :
(Error)
If the cron String isn't valid.

Adding task into your tasks.

    $ser typeod Series
    $ser.add("Hello World")
    Cron.addTask("10 0-23/6 * * 1", "Echo.echoString", $ser)
    This will execute the "Echo echoString" command with a "Hello World" parameter, every Monday on 0.10, 6.10, 12.10, 18.10
    

top
static getInstance
Returns: Cron

The cron concept is Singleton, with this method you can get an instance.

    Cron.addTask("10 0-23/6 * * 1", "Google rsearch regexp syntax flags")
    Cron.getInstance
    -- the result is --
    Cron
    tasks
    task
        id: 1   timeString: 10 0-23/6 * * 1     CommandString: Google rsearch regexp syntax flags
    

top
static getTasks
Returns: Series

Returns all the tasks.

    Cron.addTask("10 0-23/6 * * 1", "Google rsearch regexp syntax flags")
    Cron.addTask("30 14 20 * *", "Google rsearch Gnome 2.0 distribution")
    Cron.getTasks
    -- the result is --
    task
        id: 1   timeString: 10 0-23/6 * * 1     CommandString: Google rsearch regexp syntax flags
    task
        id: 2   timeString: 30 14 20 * *        CommandString: Google rsearch Gnome 2.0 distribution
    

top
static removeTask (Integer $taskId)
Parameters:
$taskId :Task id, what returns the addTask method
Returns:

Remove the specified task.

    Cron.addTask("10 0-23/6 * * 1", "Google rsearch regexp syntax flags")
    Cron.addTask("30 14 20 * *", "Google rsearch Gnome 2.0 distribution")
    Cron.removeTask(1)
    Cron.getTasks
    -- the result is --
    task
        id: 2   timeString: 30 14 20 * *        CommandString: Google rsearch Gnome 2.0 distribution
    

top
static start
Returns:
Exceptions:
onStartException :
(Error)
If the scheduler can't be started.

Starting the scheduler.

    Cron.addTask("10 0-23/6 * * 1", "Google rsearch regexp syntax flags")
    Cron.addTask("30 14 20 * *", "Google rsearch Gnome 2.0 distribution")
    Cron.start
    

top
static stop
Returns:

Stops the scheduler.

    Cron.stop
    

top