Backgroundjobs: rename ScheduledTask to QueuedTask
This commit is contained in:
parent
1ce2cd73ff
commit
ceda0ae052
|
@ -21,22 +21,22 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manages our scheduled tasks.
|
* This class manages our queued tasks.
|
||||||
*/
|
*/
|
||||||
class OC_BackgroundJob_ScheduledTask{
|
class OC_BackgroundJob_QueuedTask{
|
||||||
/**
|
/**
|
||||||
* @brief Gets one scheduled task
|
* @brief Gets one queued task
|
||||||
* @param $id ID of the task
|
* @param $id ID of the task
|
||||||
* @return associative array
|
* @return associative array
|
||||||
*/
|
*/
|
||||||
public static function find( $id ){
|
public static function find( $id ){
|
||||||
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*scheduledtasks WHERE id = ?' );
|
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*queuedtasks WHERE id = ?' );
|
||||||
$result = $stmt->execute(array($id));
|
$result = $stmt->execute(array($id));
|
||||||
return $result->fetchRow();
|
return $result->fetchRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets all scheduled tasks
|
* @brief Gets all queued tasks
|
||||||
* @return array with associative arrays
|
* @return array with associative arrays
|
||||||
*/
|
*/
|
||||||
public static function all(){
|
public static function all(){
|
||||||
|
@ -44,18 +44,17 @@ class OC_BackgroundJob_ScheduledTask{
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
// Get Data
|
// Get Data
|
||||||
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*scheduledtasks' );
|
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*queuedtasks' );
|
||||||
$result = $stmt->execute(array());
|
$result = $stmt->execute(array());
|
||||||
while( $row = $result->fetchRow()){
|
while( $row = $result->fetchRow()){
|
||||||
$return[] = $row;
|
$return[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Und weg damit
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets all scheduled tasks of a specific app
|
* @brief Gets all queued tasks of a specific app
|
||||||
* @param $app app name
|
* @param $app app name
|
||||||
* @return array with associative arrays
|
* @return array with associative arrays
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +63,7 @@ class OC_BackgroundJob_ScheduledTask{
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
// Get Data
|
// Get Data
|
||||||
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*scheduledtasks WHERE app = ?' );
|
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*queuedtasks WHERE app = ?' );
|
||||||
$result = $stmt->execute(array($app));
|
$result = $stmt->execute(array($app));
|
||||||
while( $row = $result->fetchRow()){
|
while( $row = $result->fetchRow()){
|
||||||
$return[] = $row;
|
$return[] = $row;
|
||||||
|
@ -75,7 +74,7 @@ class OC_BackgroundJob_ScheduledTask{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief schedules a task
|
* @brief queues a task
|
||||||
* @param $app app name
|
* @param $app app name
|
||||||
* @param $klass class name
|
* @param $klass class name
|
||||||
* @param $method method name
|
* @param $method method name
|
||||||
|
@ -83,21 +82,21 @@ class OC_BackgroundJob_ScheduledTask{
|
||||||
* @return id of task
|
* @return id of task
|
||||||
*/
|
*/
|
||||||
public static function add( $task, $klass, $method, $parameters ){
|
public static function add( $task, $klass, $method, $parameters ){
|
||||||
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*scheduledtasks (app, klass, method, parameters) VALUES(?,?,?,?)' );
|
$stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*queuedtasks (app, klass, method, parameters) VALUES(?,?,?,?)' );
|
||||||
$result = $stmt->execute(array($app, $klass, $method, $parameters, time));
|
$result = $stmt->execute(array($app, $klass, $method, $parameters, time));
|
||||||
|
|
||||||
return OC_DB::insertid();
|
return OC_DB::insertid();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief deletes a scheduled task
|
* @brief deletes a queued task
|
||||||
* @param $id id of task
|
* @param $id id of task
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*
|
*
|
||||||
* Deletes a report
|
* Deletes a report
|
||||||
*/
|
*/
|
||||||
public static function delete( $id ){
|
public static function delete( $id ){
|
||||||
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*scheduledtasks WHERE id = ?' );
|
$stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*queuedtasks WHERE id = ?' );
|
||||||
$result = $stmt->execute(array($id));
|
$result = $stmt->execute(array($id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -30,7 +30,7 @@ class OC_BackgroundJob_Worker{
|
||||||
* @brief executes all tasks
|
* @brief executes all tasks
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*
|
*
|
||||||
* This method executes all regular tasks and then all scheduled tasks.
|
* This method executes all regular tasks and then all queued tasks.
|
||||||
* This method should be called by cli scripts that do not let the user
|
* This method should be called by cli scripts that do not let the user
|
||||||
* wait.
|
* wait.
|
||||||
*/
|
*/
|
||||||
|
@ -41,11 +41,11 @@ class OC_BackgroundJob_Worker{
|
||||||
call_user_func( $value );
|
call_user_func( $value );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do our scheduled tasks
|
// Do our queued tasks
|
||||||
$scheduled_tasks = OC_BackgroundJob_ScheduledTask::all();
|
$queued_tasks = OC_BackgroundJob_QueuedTask::all();
|
||||||
foreach( $scheduled_tasks as $task ){
|
foreach( $queued_tasks as $task ){
|
||||||
call_user_func( array( $task['klass'], $task['method'] ), $task['parameters'] );
|
call_user_func( array( $task['klass'], $task['method'] ), $task['parameters'] );
|
||||||
OC_BackgroundJob_ScheduledTask::delete( $task['id'] );
|
OC_BackgroundJob_QueuedTask::delete( $task['id'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -82,23 +82,23 @@ class OC_BackgroundJob_Worker{
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $done == false ){
|
if( $done == false ){
|
||||||
// Next time load scheduled tasks
|
// Next time load queued tasks
|
||||||
OC_Appconfig::setValue( 'core', 'backgroundjobs_step', 'scheduled_tasks' );
|
OC_Appconfig::setValue( 'core', 'backgroundjobs_step', 'queued_tasks' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$tasks = OC_BackgroundJob_ScheduledTask::all();
|
$tasks = OC_BackgroundJob_QueuedTask::all();
|
||||||
if( count( $tasks )){
|
if( count( $tasks )){
|
||||||
$task = $tasks[0];
|
$task = $tasks[0];
|
||||||
// delete job before we execute it. This prevents endless loops
|
// delete job before we execute it. This prevents endless loops
|
||||||
// of failing jobs.
|
// of failing jobs.
|
||||||
OC_BackgroundJob_ScheduledTask::delete($task['id']);
|
OC_BackgroundJob_QueuedTask::delete($task['id']);
|
||||||
|
|
||||||
// execute job
|
// execute job
|
||||||
call_user_func( array( $task['klass'], $task['method'] ), $task['parameters'] );
|
call_user_func( array( $task['klass'], $task['method'] ), $task['parameters'] );
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Next time load scheduled tasks
|
// Next time load queued tasks
|
||||||
OC_Appconfig::setValue( 'core', 'backgroundjobs_step', 'regular_tasks' );
|
OC_Appconfig::setValue( 'core', 'backgroundjobs_step', 'regular_tasks' );
|
||||||
OC_Appconfig::setValue( 'core', 'backgroundjobs_task', '' );
|
OC_Appconfig::setValue( 'core', 'backgroundjobs_task', '' );
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,19 +32,20 @@ namespace OCP;
|
||||||
* This class provides functions to manage backgroundjobs in ownCloud
|
* This class provides functions to manage backgroundjobs in ownCloud
|
||||||
*
|
*
|
||||||
* There are two kind of background jobs in ownCloud: regular tasks and
|
* There are two kind of background jobs in ownCloud: regular tasks and
|
||||||
* scheduled tasks.
|
* queued tasks.
|
||||||
*
|
*
|
||||||
* Regular tasks have to be registered in appinfo.php and
|
* Regular tasks have to be registered in appinfo.php and
|
||||||
* will run on a regular base. Fetching news could be a task that should run
|
* will run on a regular base. Fetching news could be a task that should run
|
||||||
* frequently.
|
* frequently.
|
||||||
*
|
*
|
||||||
* Scheduled tasks have to be registered each time you want to execute them.
|
* Queued tasks have to be registered each time you want to execute them.
|
||||||
* An example of the scheduled task would be the creation of the thumbnail. As
|
* An example of the queued task would be the creation of the thumbnail. As
|
||||||
* soon as the user uploads a picture the gallery app registers the scheduled
|
* soon as the user uploads a picture the gallery app registers the queued
|
||||||
* task "create thumbnail" and saves the path in the parameter. As soon as the
|
* task "create thumbnail" and saves the path in the parameter instead of doing
|
||||||
* task is done it will be deleted from the list.
|
* the work right away. This makes the app more responsive. As soon as the task
|
||||||
|
* is done it will be deleted from the list.
|
||||||
*/
|
*/
|
||||||
class Backgroundjob {
|
class BackgroundJob {
|
||||||
/**
|
/**
|
||||||
* @brief creates a regular task
|
* @brief creates a regular task
|
||||||
* @param $klass class name
|
* @param $klass class name
|
||||||
|
@ -66,51 +67,51 @@ class Backgroundjob {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets one scheduled task
|
* @brief Gets one queued task
|
||||||
* @param $id ID of the task
|
* @param $id ID of the task
|
||||||
* @return associative array
|
* @return associative array
|
||||||
*/
|
*/
|
||||||
public static function findScheduledTask( $id ){
|
public static function findQueuedTask( $id ){
|
||||||
return \OC_BackgroundJob_ScheduledTask::find( $id );
|
return \OC_BackgroundJob_QueuedTask::find( $id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets all scheduled tasks
|
* @brief Gets all queued tasks
|
||||||
* @return array with associative arrays
|
* @return array with associative arrays
|
||||||
*/
|
*/
|
||||||
public static function allScheduledTasks(){
|
public static function allQueuedTasks(){
|
||||||
return \OC_BackgroundJob_ScheduledTask::all();
|
return \OC_BackgroundJob_QueuedTask::all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets all scheduled tasks of a specific app
|
* @brief Gets all queued tasks of a specific app
|
||||||
* @param $app app name
|
* @param $app app name
|
||||||
* @return array with associative arrays
|
* @return array with associative arrays
|
||||||
*/
|
*/
|
||||||
public static function scheduledTaskWhereAppIs( $app ){
|
public static function queuedTaskWhereAppIs( $app ){
|
||||||
return \OC_BackgroundJob_ScheduledTask::whereAppIs( $app );
|
return \OC_BackgroundJob_QueuedTask::whereAppIs( $app );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief schedules a task
|
* @brief queues a task
|
||||||
* @param $app app name
|
* @param $app app name
|
||||||
* @param $klass class name
|
* @param $klass class name
|
||||||
* @param $method method name
|
* @param $method method name
|
||||||
* @param $parameters all useful data as text
|
* @param $parameters all useful data as text
|
||||||
* @return id of task
|
* @return id of task
|
||||||
*/
|
*/
|
||||||
public static function addScheduledTask( $task, $klass, $method, $parameters ){
|
public static function addQueuedTask( $task, $klass, $method, $parameters ){
|
||||||
return \OC_BackgroundJob_ScheduledTask::add( $task, $klass, $method, $parameters );
|
return \OC_BackgroundJob_QueuedTask::add( $task, $klass, $method, $parameters );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief deletes a scheduled task
|
* @brief deletes a queued task
|
||||||
* @param $id id of task
|
* @param $id id of task
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*
|
*
|
||||||
* Deletes a report
|
* Deletes a report
|
||||||
*/
|
*/
|
||||||
public static function deleteScheduledTask( $id ){
|
public static function deleteQueuedTask( $id ){
|
||||||
return \OC_BackgroundJob_ScheduledTask::delete( $id );
|
return \OC_BackgroundJob_QueuedTask::delete( $id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue