4.4.4 • Published 23 days ago

exframe-job v4.4.4

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
23 days ago

exframe-job

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

Usage

const { createJob, applyBlockTasks, queryJobItems, updateJobItemStatus } = 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

Creates Jobs and Job items in the database and returns the job and jobItems.

Example

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

Arguments:

  • context object Required. Context object containing the user and log object
  • options object Required. object containing the jobData and jobItemData
  • options.jobData object Required. The job type

Example Arguments

/*
"jobData": {
    "type":"BOB Endorsement",
    "data": {
        "someField": "some field for metadata on the job"
    }
}
*/

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

Example Response

/*
{
  "job": {
    "_id": "611d07b04d04e62070ed0eb4",
    "type": "BOB Endorsement",
    "status": "Pending",
    "data": {
        "someField": "some field for metadata on the job"
    }
    "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
  }
}
 */

createJobItems

Creates Job items in the database and returns the jobItems that are created.

Example

const { job, jobItems } = await createJobItems(context, { jobId, jobItemData });

Arguments:

  • context object Required. Context object containing the user and log object
  • options object Required. object containing the jobData
  • options.jobId string Required. The jobId
  • options.jobItemData array Required. The array of job items

Example Arguments

/*
{
"jobId": "611d07b14d04e62070ed0eb8",
"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 array containing jobItems.

Example Response

/*
{
  "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
    }
  ]
}
 */

queryJobAndJobItems

Queries Job and Job Items by passing in a filter defined by the service making the request.

Example

const jobItemResult = await queryJobAndJobItems(context, { filter, options });

Arguments:

  • context object Required. Context object containing the user and log object
  • filter object Required. object containing params to be passed into the filter match
  • options object object containing paging options
  • options.page integer number to indicate current page
  • options.pageSize integer number to indicate limit of results for each page
  • options.sortDirection string to specify sort direction on desc for descending order and asc for ascending order
  • options.sortField string to specify field to sort by

Example Arguments

/*
filter: { _id: ObjectId('61b0c698fdb2830061266d1f'), 'data.someProperty': '2021120899', 'createdBy.userName': 'TESTUSER' },
options:  { page: 1, pageSize: 25, sortField: 'updatedAt', sortDirection: 'desc'}

*/

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

Example Response

/*
[
 {
    "_id" : "61b0c698fdb2830061266d1f",
    "data" : {
        "date" : "2021-12-08T14:52:07.157Z",
        "description" : "Payment Received",
        "someProperty" : "2021120899",
        "type" : "Electronic Deposit"
    },
    "createdBy" : {
        "_id" : "61b0c698fdb2830061266d20",
        "userName" : "TESTUSER",
        "userId" : "N4x5qctjvP"
    },
    "updatedBy" : {
        "_id" : "61b0c698fdb2830061266d21",
        "userName" : "TESTUSER",
        "userId" : "N4x5qctjvP"
    },
    "createdAt" : "2021-12-08T14:52:08.324Z",
    "updatedAt" : "2021-12-08T14:52:08.324Z",
    "jobItems" : [ 
        {
            "_id" : "61b0c698fdb2830061266d24",
            "jobId" : "61b0c698fdb2830061266d1f",
            "data" : {
                "date" : "2021-12-08T14:52:07.157Z",
                "description" : "Payment Received",
                "someProperty" : "2021120899",
                "type" : "Electronic Deposit",
                "policyNumber" : "aVdFvY-jaM",
                "amount" : 2027
            },
            "status" : "Complete",
            "createdBy" : {
                "_id" : "61b0c698fdb2830061266d25",
                "userName" : "TESTUSER",
                "userId" : "N4x5qctjvP"
            },
            "updatedBy" : {
                "_id" : "61b0c698fdb2830061266d26",
                "userName" : "TESTUSER",
                "userId" : "N4x5qctjvP"
            },
            "createdAt" : "2021-12-08T14:52:08.324Z",
            "updatedAt" : "2021-12-08T14:52:08.324Z"
        }
    ]
}   
]
 */

queryJobStatus

Queries Job status including a count of JobItem statuses

Example

const jobItemResult = await queryJobStatus(context, { jobId });

Arguments:

  • context object Required. Context object containing the user and log object
  • options object Required. object containing the jobId
  • options.jobId ObjectId Required. The job ID

Example Arguments

/*
{ jobId: ObjectId("61b0c698fdb2830061266d1f") }
*/

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

Example Response

/*
[
 {
    "_id" : "61b0c698fdb2830061266d1f",
    "data" : {
        "date" : "2021-12-08T14:52:07.157Z",
        "description" : "Payment Received",
        "someProperty" : "2021120899",
        "type" : "Electronic Deposit"
    },
    "createdBy" : {
        "_id" : "61b0c698fdb2830061266d20",
        "userName" : "TESTUSER",
        "userId" : "N4x5qctjvP"
    },
    "updatedBy" : {
        "_id" : "61b0c698fdb2830061266d21",
        "userName" : "TESTUSER",
        "userId" : "N4x5qctjvP"
    },
    "createdAt" : "2021-12-08T14:52:08.324Z",
    "updatedAt" : "2021-12-08T14:52:08.324Z",
    "jobItemStatus": {
    "Complete": 5,
    "Failed": 1,
    "Started": 0,
    "Pending": 2
    },
    "jobItemTotal" : 8
}   
]
 */

queryJobItems

Queries Job Items by jobId and optional status.

Example

const { job, jobItems } = await queryJobItems(context, { jobId, status });

Arguments:

  • context object Required. Context object containing the user and log object
  • options object Required. object containing the jobId and status
  • options.jobId string Required. The job ID
  • options.status string The status of the job items

Example Arguments

/*
{ jobId: '611bb7fb216ecd19b4ee04de', status: 'Complete' }
*/

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

Example Response

/*
[
    {
      "_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
    }
  ]
 */

updateJobItemStatus

Updates the status for a Job item.

Example

await updateJobItemStatus(context, { jobItemId, status });

Arguments:

  • context object Required. Context object containing the user and log object
  • options object Required. object containing the jobId and status
  • options.jobItemId string Required. The job ID
  • options.status string The status of the job items

Example Arguments

/*
{ jobItemId: '611bb7fb216ecd19b4ee04de', status: 'Failed' }
*/

Returns a Promise that resolves with an object containing the updated jobItem.

Example Response

/*
{
      "_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": "Failed",
      "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
    }
 */

updateJobStatus

Updates the status for a Job .

Example

await updateJobStatus(context, { jobId, status });

Arguments:

  • context object Required. Context object containing the user and log object
  • options object Required. object containing the jobId and status
  • options.jobId string Required. The job ID
  • options.status string The status of the job s

Example Arguments

/*
{ jobId: '611bb7fb216ecd19b4ee04de', status: 'Failed' }
*/

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

Example Response

/*
{
    "_id": "611d07b04d04e62070ed0eb4",
    "type": "BOB Endorsement",
    "status": "Pending",
    "data": {
        "someField": "some field for metadata on the job"
    }
    "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
  }
 */

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(wfBlock => {
        wfBlock.task('taskOne', (context, workContext) => {

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

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

        });
},
{ 
    overrideJobItemComplete: async (context, jobItem) => {},
    overrideJobComplete: async (context, job) => {},
    handleBlockPost: (context, workContext, result) => {},
    handleJobErrorCatch: (context, workContext, error) => {
        switch (error.status) {
            case 403: return 'authorize'
            default: return null;
        }
    }
});

Arguments

  • workflowBlock function Required. A function that applies workflow tasks to process a jobItem
  • options object Required. object containing options to pass to the job block
  • options.overrideJobItemComplete function A function to handle updating the job item status from within the consuming service until a change in exframe-workflow is made to support continuing a workflow after an error
  • options.overrideJobComplete function A function to handle updating the job status from within the consuming service until a change in exframe-workflow is made to support continuing a workflow after an error
  • options.handleBlockPost function A function to handle the post for the job block
  • options.handleJobErrorCatch function catch function to execute after the job is marked as failed
4.4.4

23 days ago

4.4.3

4 months ago

4.4.2

6 months ago

4.4.1

7 months ago

4.4.0

8 months ago

4.3.9

9 months ago

4.3.8

10 months ago

4.3.7

11 months ago

4.3.6

11 months ago

4.3.5

1 year ago

4.3.4

1 year ago

4.3.3

1 year ago

4.3.2

2 years ago

4.3.1

2 years ago

4.3.0

2 years ago

4.2.7

2 years ago

4.2.6

2 years ago

4.2.9

2 years ago

4.2.8

2 years ago

4.2.10

2 years ago

4.2.11

2 years ago

4.2.5

2 years ago

4.2.12

2 years ago

4.2.13

2 years ago

4.2.3

2 years ago

4.2.2

2 years ago

4.2.4

2 years ago

4.1.0

2 years ago

4.2.1

2 years ago

4.0.3

2 years ago

4.2.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

3.0.0-cc5cef6

2 years ago

3.1.1

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.2-ab40db4

2 years ago

3.0.0-596fb5e

2 years ago

3.0.1-e8a4097

2 years ago

3.0.2-c806872

2 years ago

1.0.4-54c14e8

3 years ago

1.0.4

3 years ago

2.0.0-22fd693

2 years ago

2.0.0-d62afbc

2 years ago

2.0.0-1b40ad2

2 years ago

2.0.0-7e0b4d2

2 years ago

2.0.0-b21af15

2 years ago

2.0.0-e539e75

2 years ago

1.0.4-cd415d5

3 years ago

1.0.4-7aa74cb

3 years ago

2.0.0-1f92c40

2 years ago

2.0.0

2 years ago

1.0.2-cc8950d

3 years ago

1.0.4-391ffc5

3 years ago

1.0.3-5ca3748

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago