zenstruck / schedule-bundle

Schedule Cron jobs (commands/callbacks/bash scripts) within your Symfony application.
MIT License
384 stars 20 forks source link

Correct way to configure ping options in yaml #69

Closed bpastukh closed 1 year ago

bpastukh commented 1 year ago

Hello! I'm not sure I understood how I should configure ping extension options. According to HttpClientInterface::OPTIONS_DEFAULTS, it's

ping_on_success:
      options:
        json: { "text": "success" }

But in src/DependencyInjection/Configuration.php:331 options is configured as an array of scalar

                ->arrayNode('options')
                    ->info('See HttpClientInterface::OPTIONS_DEFAULTS')
                    ->scalarPrototype()->end()
                ->end()

So I tried this way:

ping_on_success:
      options:
        json: '{ "text": "success" }'

But HTTP client converts " to \u0022. So I tried to use body option + content-type header

      options:
        body: '{ "text": "success" }'
        headers: '{ "Content-Type": "application/json" }'

And now I have problems with headers: In HttpClientTrait.php line 235:

  [TypeError]
  Argument 1 passed to Symfony\Component\HttpClient\CurlHttpClient::normalizeHeaders() must be of the type array, string given, called in /app/vendor/symfony/http-client/HttpClientTrait.php on line 162

So what's the correct way to configure ping options in yaml format?

kbond commented 1 year ago

Hey @bpastukh,

I think this should be considered a bug. I think what you want in your configuration is:

ping_on_success:
    options:
        json: 
            text: success
        headers: 
            'Content-Type': application/json

For this to work, I think we need to change:

- ->scalarPrototype()->end()
+ ->variablePrototype()->end()

Could you try this in your local project and see if it works?

bpastukh commented 1 year ago
- ->scalarPrototype()->end()
+ ->variablePrototype()->end()

yes, it works, thank you! btw, header 'Content-Type': application/json is extra if we use json option (it is set in HttpClientTrait.php:80) . So this config is correct:

 ping_on_success:
    options:
        json: 
            text: success
kbond commented 1 year ago

btw, header 'Content-Type': application/json is extra if we use json option (it is set in HttpClientTrait.php:80) .

Oh yeah.

yes, it works, thank you!

Would you be up for creating a PR?