Nosana Jobs

About 9 min

Nosana Jobs

Projects can post pipeline jobs through the Nosana Jobs program. It lets nodes in the Nosana Network earn tokens by doing those jobs.

Program Information

InfoDescription
TypeSolana Programopen in new window
Source CodeGitHubopen in new window
Build StatusAnchor Verifiedopen in new window
Accounts3
Instructions10
Types2
Domainnosana-jobs.sol
AddressnosJhNRqr2bc9g1nfGDcXXTXvYUmxD4cVwy2pMWhrYMopen in new window

Instructions

A number of 10 instruction are defined in the Nosana Jobs program.

Example

To load the program with Anchoropen in new window.

const programId = new PublicKey('nosJhNRqr2bc9g1nfGDcXXTXvYUmxD4cVwy2pMWhrYM');
const idl = await Program.fetchIdl(programId.toString());
const program = new Program(idl, programId);

Accounts

A number of 3 accounts make up for the Nosana Jobs Program's state.

Types

A number of 2 type variants are defined in the Nosana Jobs Program's state.

Finding jobs

Unclaimed Jobs

To find unclaimed jobs with Anchor:

const jobs = await program.account.jobAccount.all([
  {
    memcmp: {
      offset: 8 + 32 * 3, // the assigned node must be NULL
      bytes: systemProgram.toBase58(),
    },
  },
  {
    memcmp: {
      offset: 8 + 32 * 4, // the nodes queue
      bytes: nodes.toBase58(),
    },
  },
  {
    memcmp: {
      offset: 8 + 32 * 5 + 8, // the job status
      bytes: '1',
    },
  },
]);

Note: leave the nodes out to find jobs across all node queues.

Expired Jobs

To find jobs that have timed out, we first find all running jobs.

const jobs = await program.account.jobAccount.all([
  {
    memcmp: {
      offset: 8 + 32 * 4, // the nodes queue
      bytes: nodes.toBase58(),
    },
  },
  {
    memcmp: {
      offset: 8 + 32 * 5 + 8, // the job status
      bytes: '2',
    },
  },
]);

With the retrieved running jobs we can find jobs that have expired, by checking their start time:

for (const job of jobs) {
  if (job.account.timeStart > (Date.now() / 1e3 - nodes.jobTimeout)) {
    // claim job!
  }
}

Diagram