Jobs Program
The Jobs Program provides methods to interact with jobs, runs, and markets on the Nosana Network.
Fetching Accounts
Get Single Job
async get(address: Address, checkRun?: boolean): Promise<Job>Fetch a job account. If checkRun is true (default), automatically checks for associated run accounts to determine if a queued job is actually running.
import { address, Job } from '@nosana/kit';
const job: Job = await client.jobs.get(address('job-address'));
console.log(job.state); // JobState enum
console.log(job.price); // Job price in smallest unit
console.log(job.ipfsJob); // IPFS CID of job definition
console.log(job.timeStart); // Start timestamp (if running)Get Single Run
async run(address: Address): Promise<Run>Fetch a run account by address.
import { address, Run } from '@nosana/kit';
const run: Run = await client.jobs.run(address('run-address'));
console.log(run.job); // Associated job address
console.log(run.node); // Node executing the run
console.log(run.time); // Run start timeGet Single Market
async market(address: Address): Promise<Market>Fetch a market account by address.
import { address, Market } from '@nosana/kit';
const market: Market = await client.jobs.market(address('market-address'));
console.log(market.queueType); // MarketQueueType enum
console.log(market.jobPrice); // Market job priceGet Multiple Jobs
async multiple(addresses: Address[], checkRuns?: boolean): Promise<Job[]>Batch fetch multiple jobs by addresses.
import { address, Job } from '@nosana/kit';
const jobs: Job[] = await client.jobs.multiple([address('job-address-1'), address('job-address-2'), address('job-address-3')], true);Querying with Filters
Query All Jobs
async all(filters?: {
state?: JobState,
market?: Address,
node?: Address,
project?: Address
}, checkRuns?: boolean): Promise<Job[]>Fetch all jobs matching filter criteria using getProgramAccounts.
import { JobState, address, Job } from '@nosana/kit';
// Get all running jobs in a market
const runningJobs: Job[] = await client.jobs.all({
state: JobState.RUNNING,
market: address('market-address'),
});
// Get all jobs for a project
const projectJobs: Job[] = await client.jobs.all({
project: address('project-address'),
});Query All Runs
async runs(filters?: {
job?: Address,
node?: Address
}): Promise<Run[]>Fetch runs with optional filtering.
import { address, Run } from '@nosana/kit';
// Get all runs for a specific job
const jobRuns: Run[] = await client.jobs.runs({ job: address('job-address') });
// Get all runs on a specific node
const nodeRuns: Run[] = await client.jobs.runs({ node: address('node-address') });Query All Markets
async markets(): Promise<Market[]>Fetch all market accounts.
import { Market } from '@nosana/kit';
const markets: Market[] = await client.jobs.markets();Creating Jobs
Post a Job
async post(params: {
market: Address,
timeout: number | bigint,
ipfsHash: string,
node?: Address
}): Promise<Instruction>Create a list instruction for posting a job to a market. Returns an instruction that must be submitted to the network.
The ipfsHash parameter should contain the IPFS hash of your job definition, which describes what container to run, what commands to execute, and what resources are needed.
import { address } from '@nosana/kit';
import type { Instruction } from '@solana/kit';
// Set wallet first
client.wallet = yourWallet;
// Create job instruction
const instruction: Instruction = await client.jobs.post({
market: address('market-address'),
timeout: 3600, // Timeout in seconds
ipfsHash: 'QmXxx...', // IPFS CID of job definition
node: address('node-address'), // Optional: target specific node
});
// Submit the instruction
await client.solana.buildSignAndSend(instruction);Real-time Monitoring
The SDK provides monitoring methods using async iterators for real-time account updates via WebSocket. See the Examples section for detailed monitoring examples.
Account Types
Job
type Job = {
address: Address;
state: JobState; // QUEUED | RUNNING | COMPLETED | STOPPED
ipfsJob: string | null; // IPFS CID of job definition
ipfsResult: string | null; // IPFS CID of job result
market: Address;
node: Address;
payer: Address;
project: Address;
price: number;
timeStart: number; // Unix timestamp
timeEnd: number; // Unix timestamp
timeout: number; // Seconds
};
enum JobState {
QUEUED = 0,
RUNNING = 1,
COMPLETED = 2,
STOPPED = 3,
}Run
type Run = {
address: Address;
job: Address; // Associated job
node: Address; // Node executing the job
time: number; // Unix timestamp
};Market
type Market = {
address: Address;
queueType: MarketQueueType; // JOB_QUEUE | NODE_QUEUE
jobPrice: number;
nodeStakeMinimum: number;
jobTimeout: number;
jobType: number;
project: Address;
// ... additional fields
};
enum MarketQueueType {
JOB_QUEUE = 0,
NODE_QUEUE = 1,
}