NoBS Python

Guides

Jobs

NoBS allows you to define Jobs as part of a project. A Job is a function that runs in the NoBS execution environment. Jobs are useful for tasks such as loading data, running training jobs, performing periodic maintenance, or any task that should run on demand or on a schedule.

Jobs can be triggered manually or can be configured to run automatically on a recurring schedule using a cron expression.

Basic Job Example

Here is an example of defining a job that loads data:

python
from nobs.models import Project, Job
from nobs.secrets import S3StorageConfig

project = Project(
    name="mlops-example",
    shared_secrets=[S3StorageConfig],

    load_pokemon_data=Job(
        load_all_data,
        arguments=LoadData()
    ),
)

Explanation

  • load_all_data is the function that the job will execute.
  • arguments=LoadData() provides configuration or runtime parameters to that function.
  • shared_secrets=[S3StorageConfig] defines secrets that the job can access.

Once deployed, this job can be triggered through the NoBS CLI or dashboard.

Scheduled Jobs (Cron Jobs)

A Job can be turned into a recurring scheduled job by providing the cron_schedule parameter. This uses standard Unix-style cron syntax.

python
from nobs.models import Compute, Project, Job
from nobs.secrets import MlflowConfig, S3StorageConfig

project = Project(
    name="mlops-example",
    shared_secrets=[S3StorageConfig],

    train_pokemon_model=Job(
        train_model,
        cron_schedule="0 3 * * *",  # Runs daily at 3 AM
        arguments=TrainConfig(),
        secrets=[MlflowConfig],
        compute=Compute(
            mvcpu_limit=1000,
            mb_memory_limit=1024
        )
    ),
)

Cron Format

Cron expressions use the following structure:

* * * * *
| | | | |
| | | | └── Day of Week (0–6)
| | | └──── Month (1–12)
| | └────── Day of Month (1–31)
| └──────── Hour (0–23)
└────────── Minute (0–59)

Some common examples:

  • Every day at 3:00 AM: 0 3 * * *
  • Once per hour on the hour: 0 * * * *
  • Every 5 minutes: */5 * * * *

Configuring Compute Resources

You can specify the CPU and memory resources for a job execution environment:

python
compute=Compute(
    mvcpu_limit=1000,
    mb_memory_limit=2048,
)

This is particularly useful for model training workloads or large batch data processes.

Using Secrets in Jobs

If the function requires credentials or configuration values, the job can be provided with secret settings classes:

python
secrets=[MlflowConfig]

These secrets are securely injected into the runtime environment.

Previous
Network Application