1
0

IManager.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
  5. *
  6. * @author Marcel Klehr <mklehr@gmx.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. namespace OCP\TextToImage;
  24. use OCP\DB\Exception;
  25. use OCP\PreConditionNotMetException;
  26. use OCP\TextToImage\Exception\TaskFailureException;
  27. use OCP\TextToImage\Exception\TaskNotFoundException;
  28. use RuntimeException;
  29. /**
  30. * API surface for apps interacting with and making use of TextToImage providers
  31. * without knowing which providers are installed
  32. * @since 28.0.0
  33. */
  34. interface IManager {
  35. /**
  36. * @since 28.0.0
  37. */
  38. public function hasProviders(): bool;
  39. /**
  40. * @since 28.0.0
  41. * @return list<IProvider>
  42. */
  43. public function getProviders(): array;
  44. /**
  45. * @param Task $task The task to run
  46. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  47. * @throws TaskFailureException If something else failed. When this is thrown task status was already set to failure.
  48. * @since 28.0.0
  49. */
  50. public function runTask(Task $task): void;
  51. /**
  52. * Will schedule a TextToImage process in the background. The result will become available
  53. * with the \OCP\TextToImage\TaskSuccessfulEvent
  54. * If inference fails a \OCP\TextToImage\Events\TaskFailedEvent will be dispatched instead
  55. *
  56. * @param Task $task The task to schedule
  57. * @throws PreConditionNotMetException If no provider was registered but this method was still called
  58. * @throws Exception If there was a problem inserting the task into the database
  59. * @since 28.0.0
  60. */
  61. public function scheduleTask(Task $task) : void;
  62. /**
  63. * @throws Exception if there was a problem inserting the task into the database
  64. * @throws PreConditionNotMetException if no provider is registered
  65. * @throws TaskFailureException If the task run failed
  66. * @since 28.0.0
  67. */
  68. public function runOrScheduleTask(Task $task) : void;
  69. /**
  70. * Delete a task that has been scheduled before
  71. *
  72. * @param Task $task The task to delete
  73. * @since 28.0.0
  74. */
  75. public function deleteTask(Task $task): void;
  76. /**
  77. * @param int $id The id of the task
  78. * @return Task
  79. * @throws RuntimeException If the query failed
  80. * @throws TaskNotFoundException If the task could not be found
  81. * @since 28.0.0
  82. */
  83. public function getTask(int $id): Task;
  84. /**
  85. * @param int $id The id of the task
  86. * @param string|null $userId The user id that scheduled the task
  87. * @return Task
  88. * @throws RuntimeException If the query failed
  89. * @throws TaskNotFoundException If the task could not be found
  90. * @since 28.0.0
  91. */
  92. public function getUserTask(int $id, ?string $userId): Task;
  93. /**
  94. * @param ?string $userId
  95. * @param string $appId
  96. * @param string|null $identifier
  97. * @return Task[]
  98. * @since 28.0.0
  99. * @throws RuntimeException If the query failed
  100. */
  101. public function getUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array;
  102. }