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

Variable Output Example for Node.js is broken #1992

Closed
wrussell1999 opened this issue Nov 29, 2024 · 3 comments
Closed

Variable Output Example for Node.js is broken #1992

wrussell1999 opened this issue Nov 29, 2024 · 3 comments
Assignees
Labels
area/docs Issues related to documentation, plugin examples, blueprints, and guides

Comments

@wrussell1999
Copy link
Member

Description

https://kestra.io/docs/how-to-guides/javascript#variable-output

const requestify = require('requestify');
const Kestra = require('@kestra-io/libs');

function GetDockerImageDownloads(imageName){
  // Queries the Docker Hub API to get the number of downloads for a specific Docker image.
  var url = `https://hub.docker.com/v2/repositories/${imageName}/`
  console.log(url)
  requestify.get(url)
    .then(function(response) {
      result = JSON.parse(response.body);
      Kestra.outputs({"pull_count": result['pull_count']})
      return result['pull_count'];
    })
    .catch(function(error) {
      console.log(error);
    })
}

GetDockerImageDownloads("kestra/kestra")
id: outputs_nodejs
namespace: company.team

description: This flow will install the npm package in a Docker container, and use kestra's NodeJS Commands task to run the script.

tasks:
  - id: run_nodejs_commands
    type: io.kestra.plugin.scripts.node.Commands
    namespaceFiles:
      enabled: true
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker
    containerImage: node:slim
    warningOnStdErr: false
    beforeCommands:
      - npm install requestify
      - npm install @kestra-io/libs
    commands:
      - node outputs_nodejs.js

  - id: log_downloads
    type: io.kestra.plugin.core.log.Log
    message: "Number of downloads: {{ outputs.run_nodejs_commands.vars.pull_count }}"

Error:

ReferenceError: module is not defined
2024-11-29 16:48:54.512module.exports = Kestra;
2024-11-29 16:48:54.512^
2024-11-29 16:48:54.513Node.js v23.3.0
2024-11-29 16:48:54.513at Module._compile (node:internal/modules/cjs/loader:1528:5)
2024-11-29 16:48:54.513
2024-11-29 16:48:54.513at ModuleJobSync.runSync (node:internal/modules/esm/module_job:395:35)
2024-11-29 16:48:54.513at file:///tmp/kestra-wd/tmp/4iKJaN09OHIVpTwmo1hQor/node_modules/@kestra-io/libs/src/index.js:86:1
2024-11-29 16:48:54.513at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:329:47)
2024-11-29 16:48:54.513at loadESMFromCJS (node:internal/modules/cjs/loader:1376:24)
2024-11-29 16:48:54.513at Object..js (node:internal/modules/cjs/loader:1698:10)
2024-11-29 16:48:54.513at Module.load (node:internal/modules/cjs/loader:1303:32)
2024-11-29 16:48:54.513at TracingChannel.traceSync (node:diagnostics_channel:322:14)
2024-11-29 16:48:54.513at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
2024-11-29 16:48:54.513at Function._load (node:internal/modules/cjs/loader:1117:12)
2024-11-29 16:48:55.158io.kestra.core.models.tasks.runners.TaskException: Command failed with exit code 1
2024-11-29 16:48:55.158Command failed with exit code 1
@wrussell1999 wrussell1999 added the documentation Improvements or additions to documentation label Nov 29, 2024
@kestrabot kestrabot bot added this to Issues Nov 29, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Issues Nov 29, 2024
@wrussell1999
Copy link
Member Author

Believe this might be more a problem with the whole task, than the example

@anna-geller anna-geller added area/docs Issues related to documentation, plugin examples, blueprints, and guides and removed documentation Improvements or additions to documentation labels Feb 10, 2025
@wrussell1999
Copy link
Member Author

Should be resolved: kestra-io/plugin-scripts#192

I will test today and close if it works

@anna-geller anna-geller moved this from Backlog to In review in Issues Feb 17, 2025
@wrussell1999
Copy link
Member Author

This works on 0.21.2 so closing as complete

Image

@github-project-automation github-project-automation bot moved this from In review to Done in Issues Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs Issues related to documentation, plugin examples, blueprints, and guides
Projects
Status: Done
Development

No branches or pull requests

3 participants