Class: SampleJobManager

Class: SampleJobManager

SampleJobManager

new SampleJobManager()

Manage the translation of a job within the translation connector.
Once the job has been created and the zip file imported, the job-manager takes over the actual translation of the zip file.
The steps involved are:
  • Import all files into the LSP: status updated to "TRANSLATING" (% complete set at 0%)
  • Request files are translated into the target languages
  • Poll until complete: status updated to "DOWNLOADING" (% complete updated also added during polling - stops at 99%)
  • Download files: status updated to "TRANSLATED" (% complete updated to 100%)
  • If any steps error: status is updated to "FAILED"
Source:

Methods

createZip(jobConfig, jobDetails) → {Promise.<SampleJobManager.JobConfig>}

Create a zip file of all the downloaded translations.
Parameters:
Name Type Description
jobConfig SampleJobManager.JobConfig The configuration of the connector job to run. This information is held as metadata in the connector for the job.
jobDetails SampleJobManager.JobDetails The details of the combined job.json files.
Source:
Returns:
A promise that contains the job metadata updated with the location of the translation zip file.
Type
Promise.<SampleJobManager.JobConfig>

getJobDetails(jobConfig) → {Promise.<SampleJobManager.JobDetails>}

Get the job details from the job.json file included in the source zip file

Within the job.json file, contentTypes node provides metadata of each content type and contentItems node lists the assets.
    "contentTypes": [
        {
            "name": {content type name}
            "fields": [
                "{field name}": {
                    "caas-translation": {
                        "translate": true | false // whether the field should be translated or not
                    }
                },...
            ],
            "systemFields": [
                "file": {
                    "caas-translation": {
                        "translate": true | false // whether the native file of the asset should be translated or not
                    }
                },...
            ]
        },...
    ],
    "contentItems": [
        {
            "name": {asset name},
            "id": {GUID},
            "type": {content type name}
        },...
    ]
The folder structure differs between job types - the job types are:
An "assets" job type:
  • job.json
  • root
    • [GUID-{name}.json,...]
    • [files]
      • [GUID,...]
        • [{binary-file}]
Or a "site" job type:
  • assets
    • job.json
    • root
      • [GUID-{name}.json,...]
      • [files]
        • [GUID,...]
          • [{binary-file}]
  • site
    • job.json
    • root
Parameters:
Name Type Description
jobConfig SampleJobManager.JobConfig The configuration of the connector job to run. This information is held as metadata in the connector for the job.
Source:
Returns:
A promise that contains the details of the combined job.json files
Type
Promise.<SampleJobManager.JobDetails>

pollStatus(jobConfig, jobDetails) → {Promise}

Background task to poll the Language Service Provider and wait for the job to be 100% complete.
Parameters:
Name Type Description
jobConfig SampleJobManager.JobConfig The configuration of the connector job to run. This information is held as metadata in the connector for the job.
jobDetails SampleJobManager.JobDetails The details of the combined job.json files.
Source:
Returns:
A promise that resolves when polling gets to 100%.
Type
Promise

restartJobs()

Restart any jobs that were previously running.
This function gets called when the translation connector starts up. Any jobs that were previously running and in a state to re-start are kicked off again.
This is a background tasks and the jobs will run until the status is updated to "TRANSLATED" or "FAILED"
Source:

translateJob(jobConfig)

Translate a job whose zip file has been imported into the persistence store.
This first checks the current state of the job and executes any further steps required.
  • Import all files into the LSP: status updated to "TRANSLATING" (% complete set at 0%)
  • Request files are translated into the target languages
  • Poll until complete: status updated to "DOWNLOADING" (% complete updated also added during polling - stops at 99%)
  • Download files: status updated to "TRANSLATED" (% complete updated to 100%)
  • If any steps error: status is updated to "FAILED"
Parameters:
Name Type Description
jobConfig SampleJobManager.JobConfig The configuration of the connector job to run. This information is held as metadata in the connector for the job.
Source:

updateProgress(jobConfig) → {Promise.<SampleJobManager.JobConfig>}

Update the job progress in the job metadata.
Parameters:
Name Type Description
jobConfig SampleJobManager.JobConfig The configuration of the connector job to run. This information is held as metadata in the connector for the job.
Properties:
Name Type Description
progress number New percentage progress value.
Source:
Returns:
A promise that contains the details of the updated job metadata
Type
Promise.<SampleJobManager.JobConfig>

updateStatus(jobConfig) → {Promise.<SampleJobManager.JobConfig>}

Update the job status in the job metadata.
Parameters:
Name Type Description
jobConfig SampleJobManager.JobConfig The configuration of the connector job to run. This information is held as metadata in the connector for the job.
Properties:
Name Type Description
status 'CREATED' | 'IMPORTING' | 'TRANSLATING' | 'DOWNLOADING' | 'TRANSLATED' The new status of the job.
statusMessage string Any message to include with the status update.
Source:
Returns:
A promise that contains the details of the updated job metadata
Type
Promise.<SampleJobManager.JobConfig>

Type Definitions

contentType

Type:
  • Object
Properties:
Name Type Description
contentType.name string The name of the content type.
contentType.fields Array.<SampleJobManager.contentType.field> The fields of the content type.
Source:

file

Type:
  • Object
Properties:
Name Type Description
name string The name of the resource to translate from the job.json file.
id string The reference identifier for this resource in the job.json file.
path string The name of the file on the file system.
Source:

JobConfig

Type:
  • Object
Properties:
Name Type Description
name string Name of the connector job.
workflowId string Identifier of the Language Service Provider workflow to use to translate this job
authToken string Bearer token to use to connect to the Language Service Provider. Since the job-manager works in the background and restarts jobs, it needs access to this token.
status 'CREATED' | 'IMPORTING' | 'TRANSLATING' | 'DOWNLOADING' | 'TRANSLATED' The status of the job.
statusMessage string Any message included with the status update.
progress number Percentage progress through the translation of the job.
properties object Language Service Provider properties.
Properties
Name Type Description
id string Identifier of the job in the connector.
projectId string Identifier of the project in the Language Service Provider.
translatedZipFile string Name of the zip file containing all the translations for the job.
Source:

JobDetails

Type:
  • Object
Properties:
Name Type Description
assets object Assets resources to translate
Properties
Name Type Description
jobJSON object The job.json object for assets.
files Array.<SampleJobManager.file> The array of files that need to be translated
contentTypes Array.<SampleJobManager.contentType> The array of content types.
site object Site resources to translate
Properties
Name Type Description
jobJSON object The job.json object for site resources.
files Array.<SampleJobManager.file> The array of files that need to be translated
sourceLanguage string The source language for the job.
targetLanguages Array.<String> Array of target languages the resources will be translated into.
Source: