Skip to content
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

Updated process name to get job that horizon is processing #6

Merged
merged 3 commits into from
Jul 25, 2022

Conversation

qschmick
Copy link
Member

Updated the getProcessName method to resolve horizon tasks to the job that it is processing.

That leads to this value

horizon:work redis --name=default --supervisor=ip-123-45-678-90-Pspg:supervisor-1 --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue=default --sleep=3 --timeout=60 --tries=1

becoming this

ProcessImportFileJob

@qschmick qschmick added the enhancement New feature or request label Jul 25, 2022
@qschmick qschmick requested review from tomschlick and solflare July 25, 2022 16:30
@qschmick qschmick self-assigned this Jul 25, 2022
Copy link

@solflare solflare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, just a minor comment. Too bad there's not a better way to get the name but this will be much nicer than the current setup 🚀

} elseif (is_array($arg) && array_key_exists('commandName', $arg)) {
$command_name_parts = explode('\\', $arg['commandName']);
$name = array_pop($command_name_parts);
break 2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suuuper minor but what about?

$raw_command_name = $arg?->commandName ?? $arg['commandName'] ?? '';
$parts = explode('\\', $raw_command_name);
$name = array_pop($parts);

or we could get it all onto one line 😬:

if ($commandName = array_pop(explode('\\', $arg?->commandName ?? $arg['commandName'] ?? ''))) {
    $name = $commandName;
    break 2;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solflare These are some neat ideas. Minor issues with them:

  1. Calling a property on an array will cause a warning (Attempt to read property "commandName" on array)
  2. array_pop takes byRef so the second options (1-liners) will throw a warning.

This is part of why I set them up the way I did. I wasn't super happy with it being so verbose but didn't see an easy way to clean up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomschlick @solflare How about this:

if ($command_name = json_decode(json_encode($arg), true)['commandName'] ?? null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qschmick

Calling a property on an array will cause a warning

I thought of the same issue and did a test to check, and calling a property on an array with the null coalescing operator doesn't throw an error and properly allows the fallback

array_pop takes byRef so the second options (1-liners) will throw a warning.

Hmm that's a harder one, and it's surprising there isn't an array function for this that doesn't pass by reference

Either way the update makes sense but it means we're encoding/decoding for each line of the stack trace until (if) we come across the commandName 🤔 Not the biggest deal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solflare Nice catch with the null coalesce part, missed that in my check. We are only encoding/decoding for the class CallQueuedHandler as that is the outer check, then we encode/decode each arg under that class. Should greatly reduce the number of calls.

@qschmick qschmick merged commit da87e6e into 6.x Jul 25, 2022
@qschmick qschmick deleted the feature/resolve-horizon-processes branch July 25, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants