diff --git a/CHANGELOG.md b/CHANGELOG.md index c11e1d1..054b1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ### Changes +* [#52](https://github.com/cleverage/rest-process-bundle/issues/52) Give a code to the task ([cleverage/process-bundle#91](https://github.com/cleverage/process-bundle/issues/91)): `rest_request` (`task: rest_request`, with `cleverage/process-bundle` 5.4 or later, referencing it by `service` being deprecated there). The task has its class name as service id; fetching it directly from the service container is deprecated (`container.private`), it will be private in 4.0. The former id `cleverage_rest_process.task.request` is a deprecated alias, removed in 4.0. Update documentation, add tests. * [#50](https://github.com/cleverage/rest-process-bundle/issues/50) CI: test the lowest versions allowed by `composer.json` (`--prefer-lowest`, PHP 8.2). Raise `psr/log` to `^2 || ^3`: `cleverage/process-bundle` loggers and the test loggers use the typed `log()` signature, a fatal error with `psr/log` 1. * [#48](https://github.com/cleverage/rest-process-bundle/issues/48) `Client::geUri()` (deprecated since v3.2, use `getUri()`) triggers a deprecation at runtime with `trigger_deprecation()` (`symfony/deprecation-contracts`, now required). Add tests. * [#46](https://github.com/cleverage/rest-process-bundle/issues/46) Add a `.gitattributes`: the development files (`.docker/`, `.github/`, `tests/`, quality tools and PHPUnit configurations, `Makefile`) are no longer part of the archive installed by Composer (`dist`). diff --git a/config/services/task.yaml b/config/services/task.yaml index 575616f..7110ab9 100644 --- a/config/services/task.yaml +++ b/config/services/task.yaml @@ -1,13 +1,22 @@ services: - cleverage_rest_process.task.request: - class: CleverAge\RestProcessBundle\Task\RequestTask - public: false + _defaults: + # Public for the direct access from the service container, deprecated since 3.3: private in 4.0 + public: true + tags: + - { name: container.private, package: cleverage/rest-process-bundle, version: '3.3' } + + CleverAge\RestProcessBundle\Task\RequestTask: shared: false arguments: - '@logger' - '@cleverage_rest_process.registry.client' tags: - { name: monolog.logger, channel: cleverage_process_task } - CleverAge\RestProcessBundle\Task\RequestTask: - alias: cleverage_rest_process.task.request - public: true + - { name: cleverage.task, code: rest_request } + cleverage_rest_process.task.request: + alias: CleverAge\RestProcessBundle\Task\RequestTask + public: false + deprecated: + package: cleverage/rest-process-bundle + version: '3.3' + message: 'The "%alias_id%" service alias is deprecated, use the "rest_request" task code or the class name of the task instead. It will be removed in 4.0.' diff --git a/docs/cookbooks/api_to_dto.md b/docs/cookbooks/api_to_dto.md index 0a2c13f..00d2cc0 100644 --- a/docs/cookbooks/api_to_dto.md +++ b/docs/cookbooks/api_to_dto.md @@ -56,7 +56,7 @@ clever_age_process: help: "bin/console cleverage:process:execute app.communes_export -c codePostal:\"'46800'\"" tasks: fetch: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request error_strategy: stop options: client: apicarto_ign @@ -66,24 +66,24 @@ clever_age_process: outputs: [deserialize] deserialize: - service: '@CleverAge\ProcessBundle\Task\Serialization\DeserializerTask' + task: deserializer options: type: 'App\Dto\Commune[]' format: json outputs: [iterate] iterate: - service: '@CleverAge\ProcessBundle\Task\InputIteratorTask' + task: input_iterator outputs: [normalize] normalize: - service: '@CleverAge\ProcessBundle\Task\Serialization\NormalizerTask' + task: normalizer options: format: csv outputs: [write] write: - service: '@CleverAge\ProcessBundle\Task\File\Csv\CsvWriterTask' + task: csv_writer options: file_path: '%kernel.project_dir%/var/exports/communes_{date}.csv' ``` @@ -110,7 +110,7 @@ transformer: ```yaml # Task configuration level json_decode: - service: '@CleverAge\ProcessBundle\Task\TransformerTask' + task: transformer options: transformers: callback: diff --git a/docs/cookbooks/csv_to_api.md b/docs/cookbooks/csv_to_api.md index f36e1ea..4ad3c34 100644 --- a/docs/cookbooks/csv_to_api.md +++ b/docs/cookbooks/csv_to_api.md @@ -35,13 +35,13 @@ clever_age_process: description: 'Push the products CSV file to the catalog API' tasks: read: - service: '@CleverAge\ProcessBundle\Task\File\Csv\CsvReaderTask' + task: csv_reader options: file_path: '%kernel.project_dir%/var/data/products.csv' outputs: [build_request] build_request: - service: '@CleverAge\ProcessBundle\Task\TransformerTask' + task: transformer options: transformers: mapping: @@ -64,7 +64,7 @@ clever_age_process: outputs: [push] push: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request error_strategy: skip # A rejected line does not stop the process options: client: catalog @@ -76,10 +76,10 @@ clever_age_process: error_outputs: [log_rejected] count_pushed: - service: '@CleverAge\ProcessBundle\Task\Reporting\StatCounterTask' + task: stat_counter log_rejected: - service: '@CleverAge\ProcessBundle\Task\Reporting\LoggerTask' + task: logger options: level: warning message: 'Product rejected by the catalog API' diff --git a/docs/index.md b/docs/index.md index ad72d9f..7b4465e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,7 +21,16 @@ CleverAge\RestProcessBundle\CleverAgeRestProcessBundle::class => ['all' => true] ## Configuration -The bundle has no configuration of its own. Each API is accessed through a [REST client](reference/client.md): a +The bundle has no configuration of its own. Its task is registered as a service (non-shared) and is used in your +processes by its code, `rest_request` (`task: rest_request`, requires `cleverage/process-bundle` 5.4 or later, see its +[task definition](https://github.com/cleverage/process-bundle/blob/main/docs/reference/02-task_definition.md)). +Referencing it by its class name (`service: '@CleverAge\RestProcessBundle\Task\RequestTask'`) is deprecated since +`cleverage/process-bundle` 5.4. + +Its service id is its class name. Fetching it directly from the service container is deprecated since 3.3 (it will be +private in 4.0); its former id, `cleverage_rest_process.task.request`, is a deprecated alias since 3.3, removed in 4.0. + +Each API is accessed through a [REST client](reference/client.md): a service tagged `cleverage.rest.client`, identified by a unique code and holding the base URI of the API. ```yaml @@ -43,7 +52,7 @@ The [RequestTask](reference/tasks/request_task.md) then references this client b ```yaml # Task configuration level fetch: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request options: client: apicarto_ign url: '/codes-postaux/communes/{codePostal}' diff --git a/docs/reference/tasks/_template.md b/docs/reference/tasks/_template.md index 919390a..041cd08 100644 --- a/docs/reference/tasks/_template.md +++ b/docs/reference/tasks/_template.md @@ -7,6 +7,7 @@ Task reference -------------- * **Service**: `Fully\Qualified\ClassName` +* **Code**: `rest_task_code` (`task: rest_task_code`) * **Iterable task** _(only if it implements `IterableTaskInterface`)_ * **Blocking task** _(only if it implements `BlockingTaskInterface`)_ * **Flushable task** _(only if it implements `FlushableTaskInterface`)_ @@ -39,7 +40,7 @@ Examples ```yaml # Task configuration level code: - service: '@Fully\Qualified\ClassName' + task: task_code options: a: 1 b: 2 diff --git a/docs/reference/tasks/request_task.md b/docs/reference/tasks/request_task.md index 96eb4d4..8960e84 100644 --- a/docs/reference/tasks/request_task.md +++ b/docs/reference/tasks/request_task.md @@ -10,6 +10,7 @@ Task reference -------------- * **Service**: `CleverAge\RestProcessBundle\Task\RequestTask` +* **Code**: `rest_request` (`task: rest_request`) Accepted inputs --------------- @@ -74,7 +75,7 @@ services: ```yaml # Task configuration level entry: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request error_strategy: stop options: client: apicarto_ign @@ -90,7 +91,7 @@ entry: ```yaml # Task configuration level list_books: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request options: client: domain_sample url: '/books' @@ -107,7 +108,7 @@ list_books: ```yaml # Task configuration level entry: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request error_strategy: stop options: client: apicarto_ign @@ -126,7 +127,7 @@ entry: ```yaml # Task configuration level get_token: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request options: client: domain_sample url: '/oauth/token' @@ -147,7 +148,7 @@ get_token: ```yaml # Task configuration level update_book: - service: '@CleverAge\RestProcessBundle\Task\RequestTask' + task: rest_request error_strategy: skip options: client: domain_sample diff --git a/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php index 6b11dea..f076424 100644 --- a/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php @@ -31,15 +31,27 @@ public function testServices(): void self::assertSame(ClientRegistry::class, $container->getDefinition('cleverage_rest_process.registry.client')->getClass()); - $definition = $container->getDefinition('cleverage_rest_process.task.request'); - self::assertSame(RequestTask::class, $definition->getClass()); + // The class name is the service id + $definition = $container->getDefinition(RequestTask::class); // Tasks are stateful: each process execution must get its own instance self::assertFalse($definition->isShared()); self::assertEquals([new Reference('logger'), new Reference('cleverage_rest_process.registry.client')], $definition->getArguments()); - - // Referenced as '@' in process configurations - $alias = $container->getAlias(RequestTask::class); - self::assertSame('cleverage_rest_process.task.request', (string) $alias); - self::assertTrue($alias->isPublic()); + self::assertSame([['channel' => 'cleverage_process_task']], $definition->getTag('monolog.logger')); + // Referenced by its code in the process configurations (task: ) + self::assertSame([['code' => 'rest_request']], $definition->getTag('cleverage.task')); + // Public for the direct access from the service container, deprecated + self::assertTrue($definition->isPublic()); + self::assertSame([['package' => 'cleverage/rest-process-bundle', 'version' => '3.3']], $definition->getTag('container.private')); + + // Former id, deprecated + $deprecatedId = 'cleverage_rest_process.task.request'; + $alias = $container->getAlias($deprecatedId); + self::assertSame(RequestTask::class, (string) $alias); + self::assertFalse($alias->isPublic()); + self::assertTrue($alias->isDeprecated()); + self::assertSame( + ['package' => 'cleverage/rest-process-bundle', 'version' => '3.3', 'message' => 'The "'.$deprecatedId.'" service alias is deprecated, use the "rest_request" task code or the class name of the task instead. It will be removed in 4.0.'], + $alias->getDeprecation($deprecatedId) + ); } }