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

The job went missing! #12

Open
jingpe opened this issue Nov 8, 2024 · 6 comments
Open

The job went missing! #12

jingpe opened this issue Nov 8, 2024 · 6 comments

Comments

@jingpe
Copy link

jingpe commented Nov 8, 2024

it works for the first time when i restart the comfyUI Server or use a new workflow json

if i use the same workflow again, it will reply : the job went missing .

@jingpe
Copy link
Author

jingpe commented Nov 8, 2024

this is my server.js

import express from 'express';
import { ComfyApi, PromptBuilder, CallWrapper } from '@saintno/comfyui-sdk';
import fs from 'fs';
import { v4 as uuidv4 } from 'uuid';


const app = express();
const port = 3000;
const unique_id = uuidv4();
const api = new ComfyApi("http://localhost:8188", "unique_id");

// Load the custom workflow JSON
const workflowJson = JSON.parse(fs.readFileSync('D:/Sites/photobooth/simple.json', 'utf-8'));

app.use(express.json());

// Initialize ComfyUI API
api.on("log", (ev) => console.log(ev.detail)); // Debug logs
await api
  .init(1000, 1000) // Retry settings
  .waitForReady();

// POST endpoint for generating images based on promptText, positivePrompt, and optional negativePrompt
app.post('/generate', async (req, res) => {
    console.log("Request received at /generate");
    console.log("Request body:", req.body);

    let responseSent = false;

    try {
        const { positivePrompt, negativePrompt } = req.body;

        const promptBuilder = new PromptBuilder(
            workflowJson,
            ["postext"],
            ["negtext"],   
            ["output_image"]
        )
        .setInputNode("postext", "7.inputs.text")
        .setInputNode("negtext", "8.inputs.text")
        .setOutputNode("output_image", "11.outputs.images")

        // Disable cache check
        CallWrapper.prototype.handleCachedOutput = async function() { return null; };

        const workflowExecution = new CallWrapper(api, promptBuilder);

        workflowExecution
            .onFinished((data) => {
                if (!responseSent) {
                    responseSent = true;
                    console.log("Workflow finished, sending response");
                    res.set('Cache-Control', 'no-store');
                    res.json({ result: "success" });
                }
            })
            .onFailed((err) => {
                if (!responseSent) {
                    responseSent = true;
                    console.error("Workflow failed:", err);
                    res.status(500).json({ error: `Workflow failed: ${err.message}` });
                }
            })
            .run();

    } catch (error) {
        if (!responseSent) {
            responseSent = true;
            console.error("Server error:", error);
            res.status(500).json({ error: `Server error: ${error.message}` });
        }
    }
});


// Start the server
app.listen(port, () => {
  console.log(`Server running on http://localhost:${port}`);
});

@btaens
Copy link

btaens commented Nov 8, 2024

I have a pull request waiting that solves an issue where the original workflow json being used gets mutated by the inputs in memory.

The other possibility might be a caching issue, does it only do it with the same inputs, including seed, or different inputs as well?

Looking at your code you don't seem to be providing any inputs though, you're only defining the input and output nodes.

@tctien342
Copy link
Collaborator

tctien342 commented Nov 8, 2024

@btaens I saw @jingpe have this line

CallWrapper.prototype.handleCachedOutput = async function() { return null; };

maybe it is the problem ?

@btaens
Copy link

btaens commented Nov 8, 2024

@btaens I saw @jingpe have this line

CallWrapper.prototype.handleCachedOutput = async function() { return null; };

maybe it is the problem ?

Oh, yeah, that'd do it.

@jingpe
Copy link
Author

jingpe commented Nov 12, 2024

I have a pull request waiting that solves an issue where the original workflow json being used gets mutated by the inputs in memory.

The other possibility might be a caching issue, does it only do it with the same inputs, including seed, or different inputs as well?

Looking at your code you don't seem to be providing any inputs though, you're only defining the input and output nodes.

yes.. i am trying to accept input parameters from postman..

i tried to take out the cache check... but still doesn't work..
"CallWrapper.prototype.handleCachedOutput = async function() { return null; };"

it only happens when i use the same workflow, if i edit the workflow a little bit, save with the same filename, it will proceed...
if i use the same workflow, no matter what i have for the input, (and i have a random seed in the workflow), it will give me the same error...

@tctien342
Copy link
Collaborator

I have a pull request waiting that solves an issue where the original workflow json being used gets mutated by the inputs in memory.
The other possibility might be a caching issue, does it only do it with the same inputs, including seed, or different inputs as well?
Looking at your code you don't seem to be providing any inputs though, you're only defining the input and output nodes.

yes.. i am trying to accept input parameters from postman..

i tried to take out the cache check... but still doesn't work.. "CallWrapper.prototype.handleCachedOutput = async function() { return null; };"

it only happens when i use the same workflow, if i edit the workflow a little bit, save with the same filename, it will proceed... if i use the same workflow, no matter what i have for the input, (and i have a random seed in the workflow), it will give me the same error...

I think you just need to map the seed input and random seed each time you call the workflow!

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

No branches or pull requests

3 participants