-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preconfigutred Cron Services #719
Conversation
And this is one of the reasons why I was against enabling it only in prod: symfony/recipes-contrib#1080 (review) Unfortunately they went ahead with that anyway: symfony/recipes-contrib#1420 |
The alternative would be to adjust the documentation and ask the user to create the service. Is it planed to create a new release in the foreseeable future? |
Thanks for the contribution. I'll leave this open for the moment, as I'm unsure if I want to move in this direction. In any case, getsentry/sentry-php#1511 needs to land first. |
@will2877 Upserts for Crons were released. Besides the wording, I would stick to |
@cleptric Another approach would be to allow the crons to be configured in the bundle configuration, similar to the Scoped HttpClients. # config/packages/sentry.yaml
sentry:
monitors:
# Cron Job
sample.cronjob:
slug: 'cronjob-demo'
type: 'crontab'
schedule: '*/5 * * * *'
checkinMargin: 5,
maxRuntime: 30,
timezone: 'UTC',
# Interval
sample.interval:
slug: 'interval-demo'
type: 'interval' # or interval
schedule:
value: 30
unit: 'minute' # or hour, day, etc.
checkinMargin: 5
maxRuntime: 30
timezone: 'UTC' I still need need to check in detail if and how this is possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov points out quite some areas that are not covered by tests. Could you cover those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class seems to create a CheckIn
, not a Monitor
.
@@ -154,6 +148,23 @@ private function registerConfiguration(ContainerBuilder $container, array $confi | |||
->setDefinition('sentry.client', new Definition(Client::class)) | |||
->setPublic(false) | |||
->setFactory([$clientBuilderDefinition, 'getClient']); | |||
|
|||
// Setup Monitors. | |||
$environment = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An event should always have an environment set and defaults to production
. See https://github.com/getsentry/sentry-php/blob/master/src/Event.php#L19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, this is about a CheckIn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same naming issuse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same naming issuse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You likely want to rename the class and file.
In all honesty, I’m having an hard time understanding what we’re trying to achieve here. The factory that is just a proxy to create a |
The factory is required to inject the environment and release from the configuration file: # config/packages/sentry.yaml
when@prod:
sentry:
dsn: '%env(SENTRY_DSN)%'
options:
environment: 'production' # <--
release: '1.1.8' # <-- Debatable is if the FactoryInterface as well as the MonitorInterface are necessary or not. |
Why not simply add a |
We already have all this functionality in the base SDK, see https://docs.sentry.io/platforms/php/crons/ I would assume some more Symfony-like integration would make sense, but I'm not sure how this should look like. |
I can't find a // Example ported from the JS documentation
$checkInId = \Sentry\captureCheckIn('<monitor-slug>', \Sentry\CheckInStatus::inProgress());
// Execute your scheduled task here...
// Notify Sentry your job has completed successfully:
\Sentry\captureCheckIn('<monitor-slug>', \Sentry\CheckInStatus::ok(), $checkInId); |
Seeing as there is only scarce documentation on the scheduler component, and not everyone will adopt this immediately i would refrain from coupling this. I would stick to the solution suggested here without the interfaces. At a later point the pre-configured
|
This dose not make use of the
|
Yes, I just copied the first example I found in the doc. Actually, the definition of the export function captureCheckIn(checkIn: CheckIn, upsertMonitorConfig?: MonitorConfig): string Personally, I stand by my opinion that I don't see any new benefit in a solution like the one suggested in this PR as this method seems to provide already everything a user need. Maybe we could argue that defining the monitors in the config centralizes everything in one place, but you will have anyway to "capture the checkin" and its status in the code, so it's quite fragile as an answer. At that point, I hardly imagine why I wouldn't want to create the monitor where I need to use it, which also eases looking for occurrences in the code if I need to. |
If I am correct, this need to be added to the $hub = SentrySdk::getCurrentHub();
$monitorConfig = new \Sentry\MonitorConfig(
\Sentry\MonitorSchedule::crontab('*/5 * * * *'),
5,
30,
'UTC'
);
$checkIn = $hub->captureCheckin('<monitor-slug>', $monitorConfig, \Sentry\CheckInStatus::inProgress());
/**
* Some important task....
*/
$checkIn = $hub->captureCheckin('<monitor-slug>', $monitorConfig, \Sentry\CheckInStatus::ok(), $checkIn);
|
Closing in favour of getsentry/sentry-php#1573 |
This PR adds a pre-configured service to the Symfony service container that creates CronJobs and CheckIns that are configured using the bundle configuration.
To use it simply inject the
Sentry\SentryBundle\Cron\CronJobFactoryInterface
and create new CronJobs:This PR also required an adjustment of the flex recipe. As the bundle is only loaded in production, we will need to manually register the service int dev: