In my scenario I have a service that works with short-lived access tokens and long-lived refresh tokens. So I need to use the long-lived refresh token to get a short-lived token. Than I can get the data with the short-lived token. When short-lived expires I need to get a new one.
I saw this example in the docs where I can pass arbitrary number of parameters to the underlying library (requests):
us_corn_yield_data:
type: api.APIDataSet
url: https://quickstats.nass.usda.gov
params:
key: SOME_TOKEN
format: JSON
commodity_desc: CORN
statisticcat_des: YIELD
agg_level_desc: STATE
year: 2000
But in this case the SOME_TOKEN is the short-lived token for getting the data from the API. But what I want is to check if the short-lived token is still valid and if not request a new one with the long-lived token.
The question is: Is there a built-in support for such a use case in api.APIDataSet or in any other kedro Datasets?
Thank you!
You can use the TemplatedConfigLoader to solve this issue. When you create your config loader, you can call the utility function that has the refreshing logic for the short-lived access token and add it to the global_dict parameter of the TemplatedConfigLoader.
Alternatively, if the utility you use to refresh your access token isn't a Python utility, e.g. a binary, you can save your access token to an environment variable and follow the same approach with TemplatedConfigLoader as described above.
The rest of your pipeline code doesn't need to change.
Hi @limdauto,
This answers my question, thanks a lot.
Is it also possible to yield values from a dataset to an external service? Here is my use case for this:
I have 3 datasets with 3 nodes in my pipeline:
_save method is done with the db insert I would like to call a callback function or something similar to update an external variable. In general: Is it possible to change an external variable from a dataset?
Thank you so much!
Hi @f-istvan:
_load and _save method with custom logic. However, since you are already using a custom dataset, why can't you update the watermark inside the _save method? Where is this watermark being stored?after_node_run Hook to add your custom logic after the third node runs. One of our users created this guide on actually using Hook for some callback functionality: https://www.youtube.com/watch?v=QVEgdJnUUsQ -- you might find it helpful.In any case, I'm glad your original question was solved. Let me close this issue and if you still need help with the second question, please open another issue. This is to help us track progress on which questions still need answering.
Most helpful comment
Hi @f-istvan:
_loadand_savemethod with custom logic. However, since you are already using a custom dataset, why can't you update the watermark inside the_savemethod? Where is this watermark being stored?after_node_runHook to add your custom logic after the third node runs. One of our users created this guide on actually using Hook for some callback functionality: https://www.youtube.com/watch?v=QVEgdJnUUsQ -- you might find it helpful.In any case, I'm glad your original question was solved. Let me close this issue and if you still need help with the second question, please open another issue. This is to help us track progress on which questions still need answering.