IManager.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * @deprecated 30.0.0
  18. */
  19. interface IManager {
  20. /**
  21. * @since 28.0.0
  22. */
  23. public function hasProviders(): bool;
  24. /**
  25. * @since 28.0.0
  26. * @return list<IProvider>
  27. */
  28. public function getProviders(): array;
  29. /**
  30. * @param Task $task The task to run
  31. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  32. * @throws TaskFailureException If something else failed. When this is thrown task status was already set to failure.
  33. * @since 28.0.0
  34. */
  35. public function runTask(Task $task): void;
  36. /**
  37. * Will schedule a TextToImage process in the background. The result will become available
  38. * with the \OCP\TextToImage\TaskSuccessfulEvent
  39. * If inference fails a \OCP\TextToImage\Events\TaskFailedEvent will be dispatched instead
  40. *
  41. * @param Task $task The task to schedule
  42. * @throws PreConditionNotMetException If no provider was registered but this method was still called
  43. * @throws Exception If there was a problem inserting the task into the database
  44. * @since 28.0.0
  45. */
  46. public function scheduleTask(Task $task) : void;
  47. /**
  48. * @throws Exception if there was a problem inserting the task into the database
  49. * @throws PreConditionNotMetException if no provider is registered
  50. * @throws TaskFailureException If the task run failed
  51. * @since 28.0.0
  52. */
  53. public function runOrScheduleTask(Task $task) : void;
  54. /**
  55. * Delete a task that has been scheduled before
  56. *
  57. * @param Task $task The task to delete
  58. * @since 28.0.0
  59. */
  60. public function deleteTask(Task $task): void;
  61. /**
  62. * @param int $id The id of the task
  63. * @return Task
  64. * @throws RuntimeException If the query failed
  65. * @throws TaskNotFoundException If the task could not be found
  66. * @since 28.0.0
  67. */
  68. public function getTask(int $id): Task;
  69. /**
  70. * @param int $id The id of the task
  71. * @param string|null $userId The user id that scheduled the task
  72. * @return Task
  73. * @throws RuntimeException If the query failed
  74. * @throws TaskNotFoundException If the task could not be found
  75. * @since 28.0.0
  76. */
  77. public function getUserTask(int $id, ?string $userId): Task;
  78. /**
  79. * @param ?string $userId
  80. * @param string $appId
  81. * @param string|null $identifier
  82. * @return Task[]
  83. * @since 28.0.0
  84. * @throws RuntimeException If the query failed
  85. */
  86. public function getUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array;
  87. }