-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Poor Man's Cron #22310
Closed
Closed
[RFC] Poor Man's Cron #22310
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
da6fd1d
cli scheduler
alikon 9237d3c
the system/web scheduler plugin
alikon e057fb7
the logrotation plugin job
alikon 0cbc2f2
webcron option
alikon be83d62
tab 4
alikon 4993392
webcron option
alikon fdea076
language 1/2
alikon cd04129
language 2/2
alikon 151b731
lock() and unLock() helper
alikon ee0c8d9
logrotation options
alikon 601ce9e
plugin job logrotation
alikon 9293a72
job logrotation lang
alikon 6aa3cad
job logrotation lang
alikon 5129412
install the 2 new plugin
alikon 7564909
cli lang
alikon 3ec0979
the cli script
alikon feaaaad
cs
alikon 1626f67
drone cs
alikon 10f7eeb
drone cs
alikon 7b063b5
drone cs
alikon 1d7ac7a
drone cs
alikon b69ccbc
drone cs
alikon 45fb701
cs
alikon b62e56b
identation
alikon 501b011
atomicity of update
alikon 7fb4bfb
desc
alikon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Cli | ||
* | ||
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
/** | ||
* Scheduler CLI. | ||
* | ||
* This is a command-line script that trigger job plugin event onExecuteScheduledTask | ||
* | ||
*/ | ||
|
||
// We are a valid entry point. | ||
const _JEXEC = 1; | ||
|
||
// Load system defines | ||
if (file_exists(dirname(__DIR__) . '/defines.php')) | ||
{ | ||
require_once dirname(__DIR__) . '/defines.php'; | ||
} | ||
|
||
if (!defined('_JDEFINES')) | ||
{ | ||
define('JPATH_BASE', dirname(__DIR__)); | ||
require_once JPATH_BASE . '/includes/defines.php'; | ||
} | ||
|
||
// Get the framework. | ||
require_once JPATH_LIBRARIES . '/import.legacy.php'; | ||
|
||
// Bootstrap the CMS libraries. | ||
require_once JPATH_LIBRARIES . '/cms.php'; | ||
|
||
// Import the configuration. | ||
require_once JPATH_CONFIGURATION . '/configuration.php'; | ||
|
||
// System configuration. | ||
$config = new JConfig; | ||
define('JDEBUG', $config->debug); | ||
|
||
// Configure error reporting to maximum for CLI output. | ||
error_reporting(E_ALL); | ||
ini_set('display_errors', 1); | ||
use Joomla\Registry\Registry; | ||
|
||
// Load Library language | ||
$lang = JFactory::getLanguage(); | ||
|
||
// Try the finder_cli file in the current language (without allowing the loading of the file in the default language) | ||
$lang->load('scheduler_cli', JPATH_SITE, null, false, false) | ||
// Fallback to the finder_cli file in the default language | ||
|| $lang->load('scheduler_cli', JPATH_SITE, null, true); | ||
|
||
/** | ||
* A command line cron job to run the job plugins event. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class SchedulerCli extends JApplicationCli | ||
{ | ||
/** | ||
* Start time for the process | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
private $time = null; | ||
|
||
/** | ||
* Entry point for the Scheduler CLI script | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function doExecute() | ||
{ | ||
$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}'; | ||
$options['text_file'] = 'joomla_cli.php'; | ||
|
||
JLog::addLogger($options, JLog::INFO, array('scheduler')); | ||
|
||
try | ||
{ | ||
JLog::add( | ||
'Starting Scheduler', JLog::INFO, 'scheduler' | ||
); | ||
} | ||
catch (RuntimeException $exception) | ||
{ | ||
// Informational log only | ||
} | ||
|
||
// Print a blank line. | ||
$this->out(JText::_('SCHEDULER_CLI')); | ||
$this->out('============================'); | ||
|
||
// Initialize the time value. | ||
$this->time = microtime(true); | ||
|
||
// Remove the script time limit. | ||
@set_time_limit(0); | ||
|
||
// Fool the system into thinking we are running as JSite. | ||
$_SERVER['HTTP_HOST'] = 'domain.com'; | ||
JFactory::getApplication('site'); | ||
|
||
$this->Trigger(); | ||
|
||
// Total reporting. | ||
$this->out(JText::sprintf('SCHEDULER_CLI_PROCESS_COMPLETE', round(microtime(true) - $this->time, 3)), true); | ||
$this->out(JText::sprintf('SCHEDULER_CLI_PEAK_MEMORY_USAGE', number_format(memory_get_peak_usage(true)))); | ||
|
||
// Print a blank line at the end. | ||
$this->out(); | ||
|
||
try | ||
{ | ||
JLog::add( | ||
'Ending Scheduler:' . JText::sprintf('SCHEDULER_CLI_PROCESS_COMPLETE', round(microtime(true) - $this->time, 3)), JLog::INFO, 'scheduler' | ||
); | ||
} | ||
catch (RuntimeException $exception) | ||
{ | ||
// Informational log only | ||
} | ||
} | ||
|
||
/** | ||
* Trigger the jobs | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
private function Trigger() | ||
{ | ||
// Unleash hell | ||
JPluginHelper::importPlugin('job'); | ||
$dispatcher = \JEventDispatcher::getInstance(); | ||
|
||
// Trigger the ExecuteTask event | ||
$dispatcher->trigger('onExecuteScheduledTask', array()); | ||
|
||
} | ||
} | ||
|
||
// Instantiate the application object, passing the class name to JCli::getInstance | ||
// and use chaining to execute the application. | ||
JApplicationCli::getInstance('SchedulerCli')->execute(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add blank line above the use statement.