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

TaskMan #159

Merged
merged 30 commits into from
Mar 19, 2024
Merged

TaskMan #159

merged 30 commits into from
Mar 19, 2024

Conversation

ingalls
Copy link
Contributor

@ingalls ingalls commented Mar 12, 2024

Context

There is a need for async task management for longer running tasks than are acceptable during an http request/response cycle.

This PR introduces a framework for task management and status monitoring

  • Allow listing tasks

@nathanielrindlaub
Copy link
Member

Ref: #148

@ingalls
Copy link
Contributor Author

ingalls commented Mar 14, 2024

Example Usage

const Authorization = `Bearer [TOKEN]`

async function getStats() {
    const res = await fetch('https://oogwqd3v1f.execute-api.us-west-2.amazonaws.com/dev/external', {
        headers: {
            Authorization,
            'content-type': 'application/json',
            'x-selected-project': 'catalina'
        },
        method: 'POST',
        body: JSON.stringify({
            query: `
                query GetStats($input: QueryStatsInput!) {
                    stats(input: $input) {
                        _id
                    }
                }
            `,
            variables: {
                "input":{
                    "filters":{
                        "cameras":null,
                        "deployments":null,
                        "labels":null,
                        "createdStart":null,
                        "createdEnd":null,
                        "addedStart":null,
                        "addedEnd":null,
                        "reviewed":null,
                        "notReviewed":null,
                        "custom":null
                    }
                }
           }
        })
    });

    return await res.json();
}

async function getTask(task) {
    const res = await fetch('https://oogwqd3v1f.execute-api.us-west-2.amazonaws.com/dev/external', {
        headers: {
            Authorization,
            'content-type': 'application/json',
            'x-selected-project': 'catalina'
        },
        method: 'POST',
        body: JSON.stringify({
            query: `
                query task($input: String!) {
                    task(input: $input) {
                        _id
                        projectId
                        user
                        type
                        status
                        created
                        updated
                        output
                    }
                }
            `,
            variables: {
                input: task
           }
        })
    });

    return await res.json();
}

let stats = await getStats('default_project');
console.error(JSON.stringify(stats));

do {
    const task = await getTask(stats.data.stats._id);
    console.error(JSON.stringify(task));
    await sleep()
} while (true)


async function sleep(num = 1000) {
    return new Promise((resolve) => {
        setTimeout(resolve, num);
    })
}

Copy link
Member

@nathanielrindlaub nathanielrindlaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great @ingalls - just a few comments in there.

src/api/db/models/Image.js Outdated Show resolved Hide resolved
src/api/db/models/Project.js Outdated Show resolved Hide resolved
src/api/db/schemas/Task.js Show resolved Hide resolved
src/api/db/models/Task.js Show resolved Hide resolved
src/api/db/models/Task.js Show resolved Hide resolved
@nathanielrindlaub nathanielrindlaub merged commit 655a16c into main Mar 19, 2024
3 checks passed
@ingalls ingalls deleted the taskman branch March 27, 2024 17:15
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

Successfully merging this pull request may close these issues.

2 participants