Create a Job

The getJob() and createJob() functions let you save either an existing job or a newly created job into a variable.

Syntax

Get a Job

/**
 * Get a job by name
 * 
 * @param name name of the job
 * @return Job object
 */
public Job getJob(String name);

Create a Job

/**
 * Create job with only name
 *
 * @param name name of the job
 * @return Job object
 */
 public Job createJob(String name);


/**
 * Create job with name and query string
 *
 * @param name     name of the job
 * @param queryStr query string
 * @return Job object
 */
 public Job createJob(String name, String queryStr);


/**
 * Create job with name, query string, start time, and end time
 *
 * @param name     name of the job
 * @param queryStr query string
 * @param startAt  start time
 * @param endAt    end time
 * @return Job object
 */
 public Job createJob(String name, String queryStr, LocalDateTime startAt, LocalDateTime endAt);


/**
 * Create job with name, query string, start time, end time, and repeat string
 *
 * @param name      name of the job
 * @param queryStr  query string
 * @param startAt   start time
 * @param endAt     end time
 * @param repeatStr repeat string
 *
 @return Job object
 */
 public Job createJob(String name, String queryStr, LocalDateTime startAt, LocalDateTime endAt, String repeatStr);


/**
 * Create job with name and list of query strings
 *
 * @param name     name of the job
 * @param queryStr list of query strings
 * @return Job object
 */
 public Job createJob(String name, List<String> queryStr);


/**
 * Create job with name, list of query strings, start time, and end time
 *
 * @param name     name of the job
 * @param queryStr list of query strings
 * @param startAt  start time
 * @param endAt    end time
 * @return Job object
 */
 public Job createJob(String name, List<String> queryStr, LocalDateTime startAt, LocalDateTime endAt);

/**
 * Create job with name, list of query strings, start time, end time, and repeat string
 *
 * @param name      name of the job
 * @param queryStr  list of query strings
 * @param startAt   start time
 * @param endAt     end time
 * @param repeatStr repeat string
 * @return Job object
 */
 public Job createJob(String name, List<String> queryStr, LocalDateTime startAt, LocalDateTime endAt, String repeatStr);


/**
 * Create job with name, list of query strings, start time, end time, and repeat
 * minutes
 *
 * @param name      name of the job
 * @param queryStr  list of query strings
 * @param startAt   start time
 * @param endAt     end time
 * @param repeatMin repeat minutes
 * @return Job object
 */
 public Job createJob(String name, List<String> queryStr, LocalDateTime startAt, LocalDateTime endAt, Integer repeatMin);

Example

Get a Job

Server server = MindsDB.connect();
Job idk = server.getJob("my_job");

Create a Job

Server server = MindsDB.connect();
Job retrainJob = server.createJob("improve_model", "RETRAIN mindsdb.home_rentals_model FROM example_db (SELECT * FROM home_rentals)", null, null, "2 days");       

Alternatively, you can create a job using this syntax:

import mindsdb.models.Project;
import mindsdb.models.Model;
import mindsdb.models.KnowledgeBase;
import mindsdb.services.Job;
import mindsdb.services.Server;
import tech.tablesaw.api.Table;

public class Main {
    public static void main(String[] args) {
        Server server = MindsDB.connect();
        Project project = server.getProject("my_project");
        Model model = project.getModel("model1");
        KnowledgeBase kb = project.getKnowledgeBase("knowledge_base_name");
        Table tbl1 = Table.read().csv("path/to/tbl1.csv");

       
        try ( Job job = project.createJob("job_name", null, null, null, 1) {
            job.addQuery(model.retrain("SELECT * FROM tbl1", "database_name", null, null).toString());
            job.addQuery(model.predict(tbl1).toString());
            job.addQuery(kb.insert(tbl1).toString());
            job.addQuery("SHOW MODELS");
        } catch( Exception e) {
        
        }
    }
}

Note that this method enables a job to manipulate knowledge bases, models, tables, views, and queries, but not databases, handlers, jobs, ML engines, or projects.

Updated on