Job Functions are a function type that you can invoke when a job is executed in a Function Job Pool. You will code your custom business logic in this function, and it will be invoked at a scheduled time when a job to trigger the function is executed in the job pool.
A Job Function is a non-HTTPS function, like Event Functions. This function will not have an endpoint, and the function will only be invoked when a job is executed in the function job pool with this particular job function as its target type.
You can code your Job Function in the following runtimes:
Like the other Serverless Functions, you can create, initialize, and deploy Job Functions functions from the CLI. You can also upload your Job Function as a zip file to the console.
However, since Job Functions are non-HTTPS functions, its URL is not accessible like Basic I/O or Advanced I/O functions. To test a Job Function, you can use the following CLI command and use the function shell.
copy
$
catalyst functions:shell
A Job Function does not return any response other than determining if the function execution was a success or failure.
You can also view and monitor the performance of the Job Function using the following Catalyst DevOps components:
Logs: You can view, manage, and monitor all executions pertaining to Job Functions.
Note: To execute a Job Function successfully, without any dispatch delays, always ensure that the allocated memory of the job function is less than that of the allocated memory of the job pool. You can find out more about preventing dispatch delays from this help section.
Benefits
A Job Function can be created, initialized, and deployed using Catalyst’s robust CLI. This ensures that all dependencies that are required to deploy the function will be automatically installed when you initialize the function through CLI.
Job functions can also be created in Catalyst’s Serverless Console via the Editor.
Job functions will contain the ideal boilerplate code using which you can code any custom business logic, and the rest of the backend requirements will be handled by Catalyst.
Function Boilerplate Code
The boilerplate code present in the Job Function when you create it in the console or initialize it using the CLI is shown below:
const projectDetails = jobRequest.getProjectDetails(); // to get the current project details
const jobDetails = jobRequest.getJobDetails(); // to get the current job details
const jobMetaDetails = jobRequest.getJobMetaDetails(); // to get the current job’s meta details
const jobpoolDetails = jobRequest.getJobpoolDetails(); // to get the current function job pool’s details
const getJobCapacityAttributes = jobRequest.getJobCapacityAttributes(); // to get the current jobs capacity
const allJobParams = jobRequest.getAllJobParams(); // to get all the parameters supplied to the job function
const jobParam = jobRequest.getJobParam(‘key’); // to get the value of a particular parameter supplied to the job function
/**
CONTEXT FUNCTIONALITIES
*/
context.closeWithSuccess(); //end of application with success
// context.closeWithFailure(); //end of application with failure
};
View more
Python Job Function Boilerplate
copy
import logging
def handler(job_request, context):
logger = logging.getLogger()
logger.info(‘Hello from main.py’)
# function input: { job_details: { job_meta_details: { params: { key: 'value' } } } }
'''JobRequest Functionalities'''
job_details = job_request.get_job_details() # get the details of the current job
project_details = job_request.get_project_details() # get the details of the current project
job_meta_details = job_request.get_job_meta_details() # get the job meta of the current job
job_pool_details = job_request.get_job_pool_details() # get the current functions job pool details
job_capacity_attributes = job_request.get_job_capacity_attributes() # get the current jobs capacity
all_job_params = job_request.get_all_job_params() # get all the parameters supplied to the job function
job_param = job_request.get_job_param('key') # get the value of a particular parameter supplied to the job function
'''Context Functionalities'''
remaining_execution_time_ms = context.get_remaining_execution_time_ms() # get the maximum allowed execution time for the job functions
max_execution_time_ms = context.get_max_execution_time_ms() # get the remaining execution time for this job function
# context.close_with_failure() # conclude the function execution with a failure response
context.close_with_success() # conclude the function execution with a success response
View more
Testing Job Functions Using Catalyst CLI
Job Functions are non-HTTPS functions like Event and Integrations Functions. You cannot invoke a Job function manually, or test it in the console. However, you can generate sample payloads and test the function using the Function Shell present in the Catalyst CLI.
The following CLI command will generate a sample payload, and you can use it to test the function in the local environment.
copy
$
catalyst event:generate:job 10108000007982015 // Replace with the required Job Pool ID
You can feed this payload while you execute the required Job Function and validate the output.
Job Function Arguments
A Catalyst Job Function supports two arguments in Java: JobRequest and Context.
The JobRequest argument contains the following built-in methods:
JobRequest.getProjectDetails(): Used to get the project details, such as the project ID and project name.
JobRequest.getJobDetails(): Used to get all the details of the Job including Job ID, the Job Pool it is associated with, and Job Name.
JobRequest.getJobMetaDetails(): Used to get all the meta details of the Job including details on Execution Time, Dispatch Delay, and details on retry attempts.
JobRequest.getJobpoolDetails(): Used to get all the details of the Job Pool. The details include Job Pool ID, Job Pool Name, and Job Pool Type.
JobRequest.getJobCapacityAttributes(): Used to get all the details about the memory allocated for the Function Job Pool.
JobRequest.getAllJobParams(): Used to get all the parameters (key-value pair) passed to the function.
JobRequest.getJobParam(String key): Used to get all value of the params by passing the key as string to the function.
The Context argument contains the following built-in methods:
Context.getRemainingExecutionTimeMs(): This can be used to fetch the remaining execution time of a job function.
Context.getMaxExecutionTimeMs(): This method can be used to get the maximum execution time of a job function, which is a constant value of 15 minutes.
A Catalyst Job Function supports two arguments in Node.js: jobDetails and context.
The jobDetails argument contains the following built-in methods:
jobDetails.getJobDetails(): Used to get all the details of the Job including Job ID, the Job Pool it is associated with, and Job Name.
jobDetails.getJobMetaDetails(): Used to get all the meta details of the Job including details on Execution Time, Dispatch Delay, and details on retry attempts.
jobDetails.getJobPoolDetails(): Used to get all the details of the Job Pool. The details include Job Pool ID, Job Pool Name, and Job Pool Type.
jobDetails.getProjectDetails(): Used to get the project details, such as the project ID and project name.
jobDetails.getJobCapacityAttributes(): Used to get all the details about the memory allocated for the Function Job Pool.
jobDetails.getAllJobParams(): Used to get all the parameters (key-value pair) passed to the function.
jobDetails.getJobParam(key): Used to get all value of the params by passing the key as string to the function.
The context argument contains the following built-in methods:
context.getRemainingExecutionTimeMs(): This can be used to fetch the remaining execution time of a job function.
context.getMaxExecutionTimeMs(): This method can be used to get the maximum execution time of a job function, which is a constant value of 15 minutes.
context.closeWithSuccess(): This method can be used to mark a job’s execution as successful.
context.closeWithFailure(): This method can be used to mark a job’s execution as failure.
A Catalyst Job Function supports two arguments in Python: job_details and context.
The job_details argument contains the following built-in methods:
job_details.get_job_details(): Used to get all the details of the Job including Job ID, the Job Pool it is associated with, and Job Name.
job_details.get_job_meta_details(): Used to get all the meta details of the Job including details on Execution Time, Dispatch Delay, and details on retry attempts.
job_details.get_job_pool_details(): Used to get all the details of the Job Pool. The details include Job Pool ID, Job Pool Name, and Job Pool Type.
job_details.get_project_details(): Used to get the project details, such as the project ID and project name.
job_details.get_job_capacity_attributes(): Used to get all the details about the memory allocated for the Function Job Pool.
job_details.get_all_job_params(): Used to get all the parameters (key-value pair) passed to the function.
job_details.get_job_param(key): Used to get all value of the params by passing the key as string to the function.
The context argument contains the following built-in methods:
context.get_remaining_execution_time_ms(): This can be used to fetch the remaining execution time of a job function.
context.get_max_execution_time_ms(): This method can be used to get the maximum execution time of a job function, which is a constant value of 15 minutes.
context.close_with_success(): This method can be used to mark a job’s execution as successful.
context.close_with_failure(): This method can be used to mark a job’s execution as failure.