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

Allow job/token name to be different than component name? #12

Open
imricardoramos opened this issue Apr 23, 2020 · 2 comments
Open

Allow job/token name to be different than component name? #12

imricardoramos opened this issue Apr 23, 2020 · 2 comments
Assignees
Labels

Comments

@imricardoramos
Copy link

Should the lib be able to send a batch request for the same component, but with different props?
Eg, I was trying to do the following request:

{
  "Job1": {
    "name": "MyComponent",
    "data": {
      "title": "Foo",
      "content": "foo"
    }
  },
  "Job2": {
    "name": "MyComponent",
    "data": {
      "title": "Bar",
      "content": "bar"
    }
  }
}

However, I can only do this:

html = renderer.render({
    'MyComponent': {
        'title': 'Foo',
        'content': 'foo'
    },
    'MyComponent': {
        'title': 'Bar',
        'content': 'bar'
    }
})

which makes the first job be overridden by the second job because they have same component name (https://github.com/ornj/hypernova-python/blob/master/hypernova/__init__.py#L53).

I've taken a quick look at the nodejs and the ruby clients, and it seems they do it differently:

In Ruby (https://github.com/airbnb/hypernova-ruby/blob/master/lib/hypernova/batch.rb#L45), they make an array of jobs, and then make a hash with the keys being the index of the job in the array.

In Node(https://github.com/airbnb/hypernova-node/blob/master/src/index.js#L89), they use the component name as the job name (as in this lib)

@marteinn
Copy link
Collaborator

marteinn commented May 5, 2020

Hi @imricardoramos and thanks for the bug report (and additional research)! I will try to find the time the next couple of days to recreate the issue, will get back to you after that. Stay tuned :)

@marteinn marteinn self-assigned this May 5, 2020
@marteinn marteinn added the bug label May 5, 2020
@marteinn
Copy link
Collaborator

Thanks for your patience @imricardoramos. To first answer your question: No, it is currently not supported to retrieve more then one component per type in a batch request.

To add support for this we most likely need to change the internal data representation of the job queue to a list and introduce a feature for generating job ids.

Currently you have two choices:

  • Cleaner api but not effective: Create your own abstraction on top of hypernova and implement the logic yourself (much like Guidance needed: how to call multiple versions of the same component? airbnb/hypernova-node#14).
  • Kind of a hack but effective: You can also add metadata to the component name passed to hypernova, then while in hypernova you just remove it and continue as usual. Example: Pass the name “MyComponent.js#my-id”, then in your getComponent function in hypernova, drop the remaining #... part.

Going forward, I think taking a hard look at how the internal data representation are organized and how we can enable this functionality without breaking any api while keeping a similar api with the other client libraries out there are the way to go. This will not be solved now, but I will keep this ticket open and add proper tags to this issue and hopefully revisit in the future. If you have any ides, PR:s are very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants