1
0

IManager.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\TextToImage;
  8. use OCP\DB\Exception;
  9. use OCP\PreConditionNotMetException;
  10. use OCP\TextToImage\Exception\TaskFailureException;
  11. use OCP\TextToImage\Exception\TaskNotFoundException;
  12. use RuntimeException;
  13. /**
  14. * API surface for apps interacting with and making use of TextToImage providers
  15. * without knowing which providers are installed
  16. * @since 28.0.0
  17. */
  18. interface IManager {
  19. /**
  20. * @since 28.0.0
  21. */
  22. public function hasProviders(): bool;
  23. /**
  24. * @since 28.0.0
  25. * @return list<IProvider>
  26. */
  27. public function getProviders(): array;
  28. /**
  29. * @param Task $task The task to run
  30. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  31. * @throws TaskFailureException If something else failed. When this is thrown task status was already set to failure.
  32. * @since 28.0.0
  33. */
  34. public function runTask(Task $task): void;
  35. /**
  36. * Will schedule a TextToImage process in the background. The result will become available
  37. * with the \OCP\TextToImage\TaskSuccessfulEvent
  38. * If inference fails a \OCP\TextToImage\Events\TaskFailedEvent will be dispatched instead
  39. *
  40. * @param Task $task The task to schedule
  41. * @throws PreConditionNotMetException If no provider was registered but this method was still called
  42. * @throws Exception If there was a problem inserting the task into the database
  43. * @since 28.0.0
  44. */
  45. public function scheduleTask(Task $task) : void;
  46. /**
  47. * @throws Exception if there was a problem inserting the task into the database
  48. * @throws PreConditionNotMetException if no provider is registered
  49. * @throws TaskFailureException If the task run failed
  50. * @since 28.0.0
  51. */
  52. public function runOrScheduleTask(Task $task) : void;
  53. /**
  54. * Delete a task that has been scheduled before
  55. *
  56. * @param Task $task The task to delete
  57. * @since 28.0.0
  58. */
  59. public function deleteTask(Task $task): void;
  60. /**
  61. * @param int $id The id of the task
  62. * @return Task
  63. * @throws RuntimeException If the query failed
  64. * @throws TaskNotFoundException If the task could not be found
  65. * @since 28.0.0
  66. */
  67. public function getTask(int $id): Task;
  68. /**
  69. * @param int $id The id of the task
  70. * @param string|null $userId The user id that scheduled the task
  71. * @return Task
  72. * @throws RuntimeException If the query failed
  73. * @throws TaskNotFoundException If the task could not be found
  74. * @since 28.0.0
  75. */
  76. public function getUserTask(int $id, ?string $userId): Task;
  77. /**
  78. * @param ?string $userId
  79. * @param string $appId
  80. * @param string|null $identifier
  81. * @return Task[]
  82. * @since 28.0.0
  83. * @throws RuntimeException If the query failed
  84. */
  85. public function getUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array;
  86. }