-
Notifications
You must be signed in to change notification settings - Fork 0
Symfony7 #1
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
base: master
Are you sure you want to change the base?
Symfony7 #1
Conversation
|
@paroe Found some more issues with PhpStorm. They are fixed now and this is ready for review. |
paroe
left a comment
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.
I found some issues, mainly in the serialization of the StackTrace / Exception. I'll try to fix this
| use Doctrine\DBAL\Types\JsonType; | ||
|
|
||
| class SafeObjectType extends ObjectType | ||
| class SafeObjectType extends JsonType |
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 causes some trouble. We currently have data in the database and that is stored (in Application:87) by serializing a FlattenException. That means that jobs without an error always have N; as the value, and jobs with an error a mega long hex value that looks something like 0x4F3A35373A2253796D666F6E795C436F6D706F6....
This of course can't be handled by the JsonType, so the worker do not start if there are existing jobs.
So, we are dealing with two problems here:
- the value in the database has to become a JSON for existing jobs
- the value in the database has to become a JSON for new jobs
And a third one:
3. This has to be done ideally in a backwards compatible way so that we can migrate back if we need to and ideally have the old and the new workers running at the same time (probably not possible)
The first problem can probably be solved by a migration. But that is not backards-compatible then. So, maybe we have to consider to add a new column.
I tried json_encode for the FlattenException, but unfortunately that just returns an empty JSON object. I was not able yet to find another way to get a proper JSON from nested exceptions. I think that we maybe have to consider just saving the stacktrace as string, but then we lose some valuable information, like the exception message.
I'll try to create a JsonSerializable FlattenException; that should solve that problem. And I am thinking of either rewriting the JobSafeObject to handle both - the old and the new - style in the database. But then we still have to perform a double deployment. I think it might be easier to write a migration that rewrites the stuff in the database, but I fear that this is can't be reversed. So the better solution is probably to introduce a new column and just set the existing one always to N; until we can finally remove / rename it.
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.
As far as I remember, that's a change that I had to make. I didn't stumble across those implications during my testing. So my current status is that you don't need help with this (anymore)?
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.
yes exactly; I have pushed the updated code with all my fixes that were required (see also my other comments)
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.
I didn't stumble across those implications during my testing.
Probably because you didn't have old jobs in your database that were already executed. The stacktrace is only written when a job has been started and not when the job is still pending. So, this is an edge case that our tests can not really cover and I also only discovered this when I tried to activate the workers on Staging
| * @method Job[] findAll() | ||
| * @method Job[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
| */ | ||
| class JobRepository extends ServiceEntityRepository |
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.
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.
It was automatically created and I thought it wouldn't hurt. But then again, it does. Do you want me to remove it?
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.
I am not sure, why exactly this is an issue. I assume that we might have to rewrite the bundle's DI to fix this if we wanted to use the explicit repository. But as it is not needed I just removed it.
| public function __construct(ManagerRegistry $managerRegistry, JobManager $jobManager, EventDispatcherInterface $dispatcher, array $queueOptionsDefault, array $queueOptions) | ||
| { | ||
| parent::__construct(); | ||
| parent::__construct('jms-job-queue:run'); |
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.
I had to move the name to the constructor because the constructor calls configure at the very end. And if you then call setName after the constructor already ran you can't extend commands anymore. This normally is not a problem, but Indiana extends the RunCommand (app:jms:run) because we have to add an additional parameter ("hostname"); and this setName made our command unavailable as the original one took precendence.
And there is also some extra logic regarding aliases in the constructor that is not executed in this case, but we don't need that
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.
Oh damn, good point.
| 'memoryUsage' => memory_get_peak_usage(), | ||
| 'memoryUsageReal' => memory_get_peak_usage(true), | ||
| 'trace' => serialize($ex ? FlattenException::create($ex) : null), | ||
| 'trace' => $trace, |
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.
In the past the data was a serialized PHP object; but now it has to be valid JSON.
I also tried to add a new column for this (so that old runners that are still running can keep that column and new runners can use the new column); but this caused a lot of trouble of invalid database schemas (because of the unknown columns) and also caused trouble because of the SafeObject type; so in the end I decided that we have to make sure that either old or new runners are running exclusively and that we have to migrate the database manually if we want to switch between the runners. That is quite ugly, but the only thing that did not require implementing a custom database adapter to circumvent the validation errors
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.
I don't even think it's that ugly; it's an okay solution. Nice fix
|
@CunningFatalist I committed my changes to fix the issues that I found, see this commit. I guess I maybe should have created a new PR to make the review easier, but in the end only very few things have changed. I have just added some types to the Job entity to get rid of some of the deprecation messages |
|
|
||
| try { | ||
| $trace = json_encode($ex ? FlattenException::create($ex)->toArray() : null, JSON_THROW_ON_ERROR); | ||
| } catch (\JsonException) { |
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 could use this, but it's not really important.
|
Thanks for fixing this. The commit you linked looks good. |
most of the changes have been ported from https://github.com/schmittjoh/JMSJobQueueBundle/tree/php81

Ticket
@paroe
I will NOT merge this PR, it's just here to make your live easier.
This should fix all deprecations and composer issues.