Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
21 changes: 15 additions & 6 deletions config/services/task.yaml
Original file line number Diff line number Diff line change
@@ -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.'
12 changes: 6 additions & 6 deletions docs/cookbooks/api_to_dto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
```
Expand All @@ -110,7 +110,7 @@ transformer:
```yaml
# Task configuration level
json_decode:
service: '@CleverAge\ProcessBundle\Task\TransformerTask'
task: transformer
options:
transformers:
callback:
Expand Down
10 changes: 5 additions & 5 deletions docs/cookbooks/csv_to_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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'
Expand Down
13 changes: 11 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}'
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/tasks/_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)_
Expand Down Expand Up @@ -39,7 +40,7 @@ Examples
```yaml
# Task configuration level
code:
service: '@Fully\Qualified\ClassName'
task: task_code
options:
a: 1
b: 2
Expand Down
11 changes: 6 additions & 5 deletions docs/reference/tasks/request_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Task reference
--------------

* **Service**: `CleverAge\RestProcessBundle\Task\RequestTask`
* **Code**: `rest_request` (`task: rest_request`)

Accepted inputs
---------------
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand Down
26 changes: 19 additions & 7 deletions tests/DependencyInjection/CleverAgeRestProcessExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '@<class>' 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: <code>)
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)
);
}
}
Loading