Page tree
Skip to end of metadata
Go to start of metadata

Job Class. This supersedes using crontab directly and provides a centralized interface for executing cron like commands.

FreePBX::Job()->getAll();

If you use this to add Jobs with the correct module rawname as the first parameter during uninstallation of the module the jobs will be uninstalled, additionally enabling and/or disabling a module will enable or disable it's associated jobs

Console Commands

[root@Andrew14 pagingpro]# fwconsole job
Usage:
  job [options]

Arguments:
  command                The command to execute

Options:
      --enable=ENABLE    Enable a specific job
      --disable=DISABLE  Disable a specific job
      --run[=RUN]        Run all jobs, or optionally run a single job if job id is appended
      --list             List known jobs
      --force            Force run even if disabled or not the right time
  -h, --help             Display this help message
  -q, --quiet            Do not output any message
  -V, --version          Display this application version
      --ansi             Force ANSI output
      --no-ansi          Disable ANSI output
  -n, --no-interaction   Do not ask any interactive question
  -v|vv|vvv, --verbose   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Centralized job management

List

List all jobs

[root@Andrew14 pagingpro]# fwconsole job --list
+------+----------------+-----------+--------------+---------------------+---------+
| ID   | Module         | Job       | Cron         | Next Run            | Enabled |
+------+----------------+-----------+--------------+---------------------+---------+
| 7    | calendar       | sync      | * * * * *    | 2019-05-14 10:51:00 | Yes     |
| 10   | timeconditions | schedtc   | * * * * *    | 2019-05-14 10:51:00 | Yes     |
| 17   | dashboard      | scheduler | * * * * *    | 2019-05-14 10:51:00 | Yes     |
| 19   | userman        | syncall   | */15 * * * * | 2019-05-14 11:00:00 | Yes     |
| 8562 | pagingpro      | scheduler | * * * * *    | 2019-05-14 10:51:00 | Yes     |
+------+----------------+-----------+--------------+---------------------+---------+

Enable

Enable a specific job

[root@Andrew14 pagingpro]# fwconsole job --enable 7
Enabled job calendar::sync

Disable

Disable a specific job

[root@Andrew14 pagingpro]# fwconsole job --disable 7
Disabled job calendar::sync

Run

Run a specific job

[root@Andrew14 pagingpro]# fwconsole job --run 7
Running calendar::sync...Starting Calendar Sync...
Finished
Done

or run all jobs

[root@Andrew14 pagingpro]# fwconsole job --run 7
Running calendar::sync...Starting Calendar Sync...
Finished
Done
[root@Andrew14 pagingpro]# fwconsole job --run
Running calendar::sync...Starting Calendar Sync...
Finished
Done
Running timeconditions::schedtc...==Working with TimeCondition:Test==
INVERTED BLF: false (NOT_INUSE = NOT_INUSE & INUSE = INUSE)
OVERRIDE MODE: not set
=>00:00-01:00|sun-sat|1|* is not now
TIME MATCHED: False (INUSE)
BLF MODE: False (INUSE)
Privilege: Command
Changing TC1 to INUSE


Done
Running dashboard::scheduler...Done
Running pagingpro::scheduler...Done

Force

Force run even if disabled or not the right time

[root@Andrew14 pagingpro]# fwconsole job --run 19
Skipping userman::syncall because schedule does not match
[root@Andrew14 pagingpro]# fwconsole job --run 19 --force
Running userman::syncall...Directory 'Imported freepbx directory' does not support syncing
Directory 'sdfdsf' does not support syncing
Done

Function Calls

getAll()

Get All Jobs

public function getAll() {}

getAllEnabled()

Get all enabled jobs

/**
 * Get all enabled jobs
 *
 * @return array
 */
public function getAllEnabled() {}

addCommand()

Add/Update Job CLI Command

/**
 * Add Job Command
 *
 * Add a job that will launch a command
 *
 * @param string $modulename The module rawname (used for uninstalling)
 * @param string $jobname The job name
 * @param string $command The CLI command to run
 * @param string $schedule The Cron Expression when to run
 * @param integer $max_runtime The max run time in seconds
 * @param boolean $enabled Whether this job is enabled or not
 * @return void
 */
public function addCommand($modulename, $jobname, $command, $schedule, $max_runtime = 30, $enabled = true) {}

addClass()

Add/Update a Job Class

/**
 * Add Job Class
 *
 * @param string $modulename The module rawname (used for uninstalling)
 * @param string $jobname The job name
 * @param string $class The class to run. Must implement https://github.com/FreePBX/framework/blob/feature/newcrons/amp_conf/htdocs/admin/libraries/BMO/Job/Job.php
 * @param string $schedule The Cron Expression when to run
 * @param integer $max_runtime The max run time in seconds
 * @param boolean $enabled Whether this job is enabled or not
 * @return void
 */
public function addClass($modulename, $jobname, $class, $schedule, $max_runtime = 30, $enabled = true) {}

remove()

Remove a job by modulename and jobname

/**
 * Remove a job by modulename and jobname
 *
 * @param string $modulename The module rawname (used for uninstalling)
 * @param string $jobname The job name
 * @return void
 */
public function remove($modulename, $jobname) {}

removeAllByModule()

Remove all jobs by module rawname

/**
 * Remove all jobs by module name
 *
 * @param string $modulename The module rawname (used for uninstalling)
 * @return void
 */
public function removeAllByModule($modulename) {}

setEnabled()

Toggle Enabled on a job

/**
 * Toggle Enabled on a job
 *
 * @param string $modulename The module rawname (used for uninstalling)
 * @param string $jobname The job name
 * @param boolean $enabled Whether this job is enabled or not
 * @return void
 */
public function setEnabled($modulename, $jobname, $enabled = true) {}

setEnabledByModule()

Set Enabled by Module Rawname

/**
 * Set Enabled by Module Rawname
 *
 * @param string $modulename
 * @param boolean $enabled
 * @return void
 */
public function setEnabledByModule($modulename, $enabled = true) {}

updateSchedule()

Update the schedule of a job that already exists

/**
 * Update schedule of a job
 *
 * @param string $modulename The module rawname (used for uninstalling)
 * @param string $jobname The job name
 * @param string $schedule The Cron Expression when to run
 * @return void
 */
public function updateSchedule($modulename, $jobname, $schedule) {}



  • No labels