Giter VIP home page Giter VIP logo

Comments (3)

inlife avatar inlife commented on May 28, 2024

Hey
Could you show the code you are using?

from nexrender.

RezaRamezanisani avatar RezaRamezanisani commented on May 28, 2024

hey
this is my code worker:

const { start } = require('@nexrender/worker');

const main = async () => {
    const serverHost = '...'
    const serverSecret = '...'
    await start(serverHost, serverSecret, {
        workpath: 'C:\\Users\\Administrator\\AppData\\Local\\Temp\\nexrender2',
        binary: '/Users/mynames/Apllications/aerender',
        skipCleanup: true,
        tagSelector: false,
        addLicense: false,
        debug: true,
        stopOnError:false
    });
}
main().catch(console.error);

and this code js for preDwonload action:

const axios = require('axios');
const fs = require('fs');
const AdmZip = require('adm-zip');
      const { updateStatus } = require('./updateStatus');

module.exports = (job, settings, action, type) => {
  job.onChange = (job, state) => {
    switch (state) {
      case 'render:dorender':
        updateStatus('2', job.uid, job.startedAt);
        break;
      case 'render:cleanup':
          if(!job.error){
              updateStatus('3', job.uid, job.finishedAt);
          }else{
              updateStatus('6', job.uid, job.errorAt);
          }
        break;
        case 'error' :
       updateStatus('6', job.uid, job.errorAt);
    }
  };

  job.onRenderProgress = (job, progress) => {
    let host = '...';
    axios
      .patch(`${host}/api/v1/user-project-output/update-progress/${action.id}`, {
        progress: progress,
      })
      .then((response) => {
        if (response.data.status === 'success') {
          console.log(response.data.message);
        } else if (response.data.status === 'error') {
          console.log(response.data.message);
        }
      })
      .catch((error) => {
        console.error(error);
      });
  };

  const url = action.url;
  const extractToPath = action.extractToPath;
  const userOutputPath = action.userOutputPath;
  const fileName = url.split('/').pop();
  const filePath = `${extractToPath}/${fileName}`;

  return new Promise((resolve, reject) => {
    // Check if the directory exists, create it if it doesn't
    if (!fs.existsSync(extractToPath)) {
      console.log(`Directory ${extractToPath} does not exist. Creating...`);
      fs.mkdirSync(extractToPath, { recursive: true });
    }

    if (!fs.existsSync(userOutputPath)) {
      console.log(`Directory ${userOutputPath} does not exist. Creating...`);
      fs.mkdirSync(userOutputPath, { recursive: true });
    }

	console.log(filePath);
    // Check if the file already exists in the directory
    if (fs.existsSync(filePath)) {
      console.log(`File ${fileName} already exists in ${extractToPath}`);
      // Skip the download and extraction steps
      resolve();
    } else {
      // Download the file from the URL
      axios({
        url: url,
        method: 'GET',
        responseType: 'arraybuffer',
      })
        .then((response) => {
          const data = new Uint8Array(response.data);
			console.log(`Start Project File  ${fileName} Download`);
          fs.writeFile(filePath, data, (err) => {
            if (err) {
              console.error(`Error downloading ${fileName}: ${err}`);
              reject(err);
            } else {
              console.log(`Download of ${fileName} complete`);

              // Extract the file to the specified folder
              const zip = new AdmZip(filePath);
              zip.extractAllTo(extractToPath, true);

              console.log(`Extraction of ${fileName} complete`);

              // Delete the downloaded zip file
              // fs.unlinkSync(filePath);

              resolve();
            }
          });
        })
        .catch((error) => {
          console.error(`Error downloading ${fileName}: ${error}`);
          reject(error);
        });
    }
  });
};

and at last :

const axios = require("axios");
const baseURL = '.../api/v1';

async function updateStatus(statusRender, jobUid, time, error = null) {
    try {
        const response = await axios.patch(`${baseURL}/user-project-output/update-status/${jobUid}`, {
            statusRender: statusRender,
            error: error,
            time: time,
            server: ''
        });

        if (response.data.status === 'success') {
            console.log(response.data.message);
        } else if (response.data.status === 'error') {
            console.log(response.data.message);
        }
    } catch (error) {
        console.error(error);
    }
}

module.exports = { updateStatus };

please help me.

from nexrender.

stale avatar stale commented on May 28, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from nexrender.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.