1.0.2 • Published 3 years ago

mark-job-module-test v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

exframe-job

A module for jobs and job items while integrating with exframe-workflow to execute job items.

Usage

const { createJob, applyJobTasks } = initialize({ workflow, dbClient });

Initialize Arguments

  • workflow - Required. The workflow instance created by the consuming service to be passed into the module.

  • dbClient - Required. The database client using to store jobs and jobItems

Methods

createJob

Starts polling the database for actions that need to be executed.

Example

const { job, jobItems } = await createJob(context, { jobData, jobItemData });

Arguments:

  • context object Required. Context object containing the user and log object
  • jobData object Required. The job type
  • jobItemData array Required. Array of job items. Job items will be stored in the DB. Job items will include all data needed to execute

Example Arguments

/*
"jobData": {
    "type":"BOB Endorsement"
}
*/
/*
"jobItemData": [
    {
      "agencyCodeFrom": 643,
      "agencyCodeTo": 295,
      "agentCodeFrom": 584,
      "agentCodeTo": 677,
      "policyNumber": "54-2444157-01",
      "agencyNameTo": "Joe - Smith",
      "agentNameTo": "Steve Adams",
      "agencyNameFrom": "John - Jacobs",
      "agentNameFrom": "Marion Miller",
      "transactionType": "BOB Endorsement"
    }
]
*/

Returns a Promise that resolves with an object containing the job and jobItems.

Example Response

/*
{
  "job": {
    "_id": "611d07b04d04e62070ed0eb4",
    "type": "BOB Endorsement",
    "status": "Pending",
    "createdBy": {
      "_id": "611d07a84d04e62070ed0e50",
      "userName": "TESTUSER",
      "userId": "eD1wfj9HGr"
    },
    "updatedBy": {
      "_id": "611d07a84d04e62070ed0e51",
      "userName": "TESTUSER",
      "userId": "eD1wfj9HGr"
    },
    "createdAt": "2021-08-18T13:14:16.227Z",
    "updatedAt": "2021-08-18T13:14:16.227Z",
    "__v": 0
  },
  "jobItems": [
    {
      "_id": "611d07b14d04e62070ed0eb8",
      "jobId": "611d07b04d04e62070ed0eb4",
      "data": {
        "agencyCodeFrom": 643,
        "agencyCodeTo": 295,
        "agentCodeFrom": 584,
        "agentCodeTo": 677,
        "policyNumber": "54-2444157-01",
        "agencyNameTo": "Joe - Fisher",
        "agentNameTo": "Henry Adams",
        "agencyNameFrom": "Jake - Jacobs",
        "agentNameFrom": "Mac Brown",
        "transactionType": "BOB Endorsement"
      },
      "status": "Pending",
      "createdBy": {
        "_id": "611d07b14d04e62070ed0eb9",
        "userName": "TESTUSER",
        "userId": "ULZzlYVSjI"
      },
      "updatedBy": {
        "_id": "611d07b14d04e62070ed0eba",
        "userName": "TESTUSER",
        "userId": "ULZzlYVSjI"
      },
      "createdAt": "2021-08-18T13:14:24.998Z",
      "updatedAt": "2021-08-18T13:14:24.998Z",
      "__v": 0
    }
  ]
}
 */

applyBlockTasks

Applies a block of tasks to the existing workflow that was originally passed in. This will be the block of tasks that will execute for each jobItem. This function is responsible for starting the job. The sourceIterator will then iterate over each jobItem that matches the jobId and attempt to start the job item (Set job status to "Started") The workflow block will then process the jobItem and set the status for each jobItem (Set jobItem status to "Complete" or "Failed") After iterating through each jobItem, the status for the job will be set (Set job status to "Complete" or "Failed")

Example

 await applyBlockTasks({
    workflowBlock: wfBlock => {
        wfBlock.task('taskOne', (context, workContext) => {

        });
        wfBlock.task('taskTwo', (context, workContext) => {

        });
        wfBlock.task('taskThree', (context, workContext) => {

        });
    }
});

Arguments

  • workflowBlock function Required. A function that applies workflow tasks to process a jobItem