You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backgroundjob.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Jakob Sack
  6. * @copyright 2012 Jakob Sack owncloud@jakobsack.de
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Public interface of ownCloud forbackground jobs.
  24. */
  25. // use OCP namespace for all classes that are considered public.
  26. // This means that they should be used by apps instead of the internal ownCloud classes
  27. namespace OCP;
  28. /**
  29. * This class provides functions to manage backgroundjobs in ownCloud
  30. *
  31. * There are two kind of background jobs in ownCloud: regular tasks and
  32. * queued tasks.
  33. *
  34. * Regular tasks have to be registered in appinfo.php and
  35. * will run on a regular base. Fetching news could be a task that should run
  36. * frequently.
  37. *
  38. * Queued tasks have to be registered each time you want to execute them.
  39. * An example of the queued task would be the creation of the thumbnail. As
  40. * soon as the user uploads a picture the gallery app registers the queued
  41. * task "create thumbnail" and saves the path in the parameter instead of doing
  42. * the work right away. This makes the app more responsive. As soon as the task
  43. * is done it will be deleted from the list.
  44. */
  45. class BackgroundJob {
  46. /**
  47. * @brief get the execution type of background jobs
  48. * @return string
  49. *
  50. * This method returns the type how background jobs are executed. If the user
  51. * did not select something, the type is ajax.
  52. */
  53. public static function getExecutionType() {
  54. return \OC_BackgroundJob::getExecutionType();
  55. }
  56. /**
  57. * @brief sets the background jobs execution type
  58. * @param $type execution type
  59. * @return boolean
  60. *
  61. * This method sets the execution type of the background jobs. Possible types
  62. * are "none", "ajax", "webcron", "cron"
  63. */
  64. public static function setExecutionType( $type ) {
  65. return \OC_BackgroundJob::setExecutionType( $type );
  66. }
  67. /**
  68. * @brief creates a regular task
  69. * @param $klass class name
  70. * @param $method method name
  71. * @return true
  72. */
  73. public static function addRegularTask( $klass, $method ) {
  74. return \OC_BackgroundJob_RegularTask::register( $klass, $method );
  75. }
  76. /**
  77. * @brief gets all regular tasks
  78. * @return associative array
  79. *
  80. * key is string "$klass-$method", value is array( $klass, $method )
  81. */
  82. static public function allRegularTasks() {
  83. return \OC_BackgroundJob_RegularTask::all();
  84. }
  85. /**
  86. * @brief Gets one queued task
  87. * @param $id ID of the task
  88. * @return associative array
  89. */
  90. public static function findQueuedTask( $id ) {
  91. return \OC_BackgroundJob_QueuedTask::find( $id );
  92. }
  93. /**
  94. * @brief Gets all queued tasks
  95. * @return array with associative arrays
  96. */
  97. public static function allQueuedTasks() {
  98. return \OC_BackgroundJob_QueuedTask::all();
  99. }
  100. /**
  101. * @brief Gets all queued tasks of a specific app
  102. * @param $app app name
  103. * @return array with associative arrays
  104. */
  105. public static function queuedTaskWhereAppIs( $app ) {
  106. return \OC_BackgroundJob_QueuedTask::whereAppIs( $app );
  107. }
  108. /**
  109. * @brief queues a task
  110. * @param $app app name
  111. * @param $klass class name
  112. * @param $method method name
  113. * @param $parameters all useful data as text
  114. * @return id of task
  115. */
  116. public static function addQueuedTask( $app, $klass, $method, $parameters ) {
  117. return \OC_BackgroundJob_QueuedTask::add( $app, $klass, $method, $parameters );
  118. }
  119. /**
  120. * @brief deletes a queued task
  121. * @param $id id of task
  122. * @return true/false
  123. *
  124. * Deletes a report
  125. */
  126. public static function deleteQueuedTask( $id ) {
  127. return \OC_BackgroundJob_QueuedTask::delete( $id );
  128. }
  129. }