pip_services_jobs 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

Pip.Services Logo
Jobs microservice #

This is the jobs microservice. It keeps list of working jobs.

The service allows you to manage tasks in those cases when the generation (statement) of the task is performed in a separate microservice, and direct execution is implemented in one way or another. One of the application options, see the following diagram:

To create a task, a simplified data model is used which should contain the following information:

  • type - task type
  • ref_id - identifier of the object on which the task will work
  • ttl - the maximum lifetime of the task before its execution
  • params - additional parameters necessary to complete the task

The created task is stored in the following form:

  • id unique identifier
  • type - task type
  • ref_id - identifier of the object on which the task will work
  • params - additional parameters necessary to complete the task
  • created - time stamp for creating a task
  • started - time stamp of the task start
  • locked_until - task lock time stamp
  • execute_until - time stamp of task execution restriction
  • completed - time stamp for completing a task
  • retries - number of starts

Task management is carried out through the API described below.

The microservice currently supports the following deployment options:

  • Deployment platforms: Standalone Process
  • External APIs: HTTP/REST
  • Persistence: Memory, Flat Files, MongoDB

Quick Links:

Contract #

Logical contract of the microservice is presented below. For physical implementation (HTTP/REST), please, refer to documentation of the specific protocol.

class NewJobV1 {
  String type;
  String ref_id;
  num ttl;
  dynamic params;
}

class JobV1 implements IStringIdentifiable {
  // Job description
  String id;
  String type;
  String ref_id;
  dynamic params;

  // Job control
  DateTime created;
  DateTime started;
  DateTime locked_until;
  DateTime execute_until;
  DateTime completed;
  num retries;
}

abstract class IJobsV1 {
  Future<JobV1> addJob(String correlationId, NewJobV1 newJob);

  Future<JobV1> addUniqJob(String correlationId, NewJobV1 newJob);

  Future<DataPage<JobV1>> getJobs(
      String correlationId, FilterParams filter, PagingParams paging);

  Future<JobV1> getJobById(String correlationId, String jobId);

  Future<JobV1> startJobById(String correlationId, String jobId, num timeout);

  Future<JobV1> startJobByType(
      String correlationId, String jobType, num timeout, num maxRetries);

  Future<JobV1> extendJob(String correlationId, String jobId, num timeout);

  Future<JobV1> abortJob(String correlationId, String jobId);
  
  Future<JobV1> completeJob(String correlationId, String jobId);

  Future<JobV1> deleteJobById(String correlationId, String jobId);

  Future deleteJobs(String correlationId);

  Future cleanJobs(String correlationId);
}

Download #

Right now the only way to get the microservice is to check it out directly from github repository

git clone git@github.com:pip-services-infrastructure/pip-services-jobs-dart.git

Pip.Service team is working to implement packaging and make stable releases available for your as zip downloadable archieves.

Run #

Add config.yaml file to the root of the microservice folder and set configuration parameters.

Example of microservice configuration

---
# Container descriptor
- descriptor: "pip-services:context-info:default:default:1.0"
  name: "pip-services-jobs"
  description: "Jobs microservice for pip-services"

# Console logger
- descriptor: "pip-services:logger:console:default:1.0"
  level: "trace"

# Performance counters that posts values to log
- descriptor: "pip-services:counters:log:default:1.0"
  level: "trace"

{{#MEMORY_ENABLED}}
# In-memory persistence. Use only for testing!
- descriptor: "pip-services-jobs:persistence:memory:default:1.0"
{{/MEMORY_ENABLED}}

{{#FILE_ENABLED}}
# File persistence. Use it for testing of for simple standalone deployments
- descriptor: "pip-services-jobs:persistence:file:default:1.0"
  path: {{FILE_PATH}}{{^FILE_PATH}}"./data/jobs.json"{{/FILE_PATH}}
{{/FILE_ENABLED}}

{{#MONGO_ENABLED}}
# MongoDB Persistence
- descriptor: "pip-services-jobs:persistence:mongodb:default:1.0"
  collection: {{MONGO_COLLECTION}}{{^MONGO_COLLECTION}}jobs{{/MONGO_COLLECTION}}
  connection:
    uri: {{{MONGO_SERVICE_URI}}}
    host: {{{MONGO_SERVICE_HOST}}}{{^MONGO_SERVICE_HOST}}localhost{{/MONGO_SERVICE_HOST}}
    port: {{MONGO_SERVICE_PORT}}{{^MONGO_SERVICE_PORT}}27017{{/MONGO_SERVICE_PORT}}
    database: {{MONGO_DB}}{{#^MONGO_DB}}app{{/^MONGO_DB}}
  credential:
    username: {{MONGO_USER}}
    password: {{MONGO_PASS}}
{{/MONGO_ENABLED}}

{{^MEMORY_ENABLED}}{{^FILE_ENABLED}}{{^MONGO_ENABLED}}
# Default in-memory persistence
- descriptor: "pip-services-jobs:persistence:memory:default:1.0"
{{/MONGO_ENABLED}}{{/FILE_ENABLED}}{{/MEMORY_ENABLED}}

# Default controller
- descriptor: "pip-services-jobs:controller:default:default:1.0"

# Common HTTP endpoint
- descriptor: "pip-services:endpoint:http:default:1.0"
  connection:
    protocol: "http"
    host: "0.0.0.0"
    port: 8080

# HTTP endpoint version 1.0
- descriptor: "pip-services-jobs:service:http:default:1.0"

# Heartbeat service
- descriptor: "pip-services:heartbeat-service:http:default:1.0"

# Status service
- descriptor: "pip-services:status-service:http:default:1.0"

For more information on the microservice configuration see Configuration Guide.

Start the microservice using the command:

dart ./bin/run.dart

Use #

The easiest way to work with the microservice is to use client SDK. The complete list of available client SDKs for different languages is listed in the Quick Links

If you use dart, then get references to the required libraries:

Add pip-services3-commons-dart, pip-services3-rpc-dart and pip-services_jobs packages

import 'package:pip_services3_commons/pip_services3_commons.dart';
import 'package:pip_services3_rpc/pip_services3_rpc.dart';

import 'package:pip_services_jobs/pip_services_jobs.dart';

Define client configuration parameters that match the configuration of the microservice's external API

// Client configuration
var httpConfig = ConfigParams.fromTuples(
	"connection.protocol", "http",
	"connection.host", "localhost",
	"connection.port", 8080
);

Instantiate the client and open connection to the microservice

// Create the client instance
var client = JobsHttpClientV1(config);

// Configure the client
client.configure(httpConfig);

// Connect to the microservice
try{
  await client.open(null)
}catch() {
  // Error handling...
}       
// Work with the microservice
// ...

Now the client is ready to perform operations

// Create a new job
final JOB = NewJobV1(
    type: 't1', ref_id: 'obj_0fsd', ttl: 1000 * 60 * 60 * 3, params: null);

    // Create the job
    try {
      JobV1 job1 = await client.createJob('123', JOB);
      // Do something with the returned job...
    } catch(err) {
      // Error handling...     
    }
// Get the job
try {
var job = await client.getJobByid(
    null,
    job1.id);
    // Do something with job...

    } catch(err) { // Error handling}

Acknowledgements #

This microservice was created and currently maintained by

  • Sergey Seroukhov
  • Nuzhnykh Egor.

1.0.0 #

  • Initial version

example/README.md

Examples for Jobs Microservice #

This is the jobs microservice. It keeps list of working jobs.

The service allows you to manage tasks in those cases when the generation (statement) of the task is performed in a separate microservice, and direct execution is implemented in one way or another.

Define configuration parameters that match the configuration of the microservice's external API

// Service/Client configuration
var httpConfig = ConfigParams.fromTuples(
	"connection.protocol", "http",
	"connection.host", "localhost",
	"connection.port", 8080
);

Instantiate the service

persistence = JobsMemoryPersistence();
persistence.configure(ConfigParams());

controller = JobsController();
controller.configure(ConfigParams());

service = JobsHttpServiceV1();
service.configure(httpConfig);

var references = References.fromTuples([
    Descriptor('pip-services-jobs', 'persistence', 'memory',
        'default', '1.0'),
    persistence,
    Descriptor('pip-services-jobs', 'controller', 'default',
        'default', '1.0'),
    controller,
    Descriptor(
        'pip-services-jobs', 'service', 'http', 'default', '1.0'),
    service
]);

controller.setReferences(references);
service.setReferences(references);

await persistence.open(null);
await service.open(null);

Instantiate the client and open connection to the microservice

// Create the client instance
var client = JobsHttpClientV1(config);

// Configure the client
client.configure(httpConfig);

// Connect to the microservice
try{
  await client.open(null)
}catch() {
  // Error handling...
}       
// Work with the microservice
// ...

Now the client is ready to perform operations

// Create a new job
final JOB = NewJobV1(
    type: 't1', ref_id: 'obj_0fsd', ttl: 1000 * 60 * 60 * 3, params: null);

    // Create the job
    try {
      JobV1 job1 = await client.createJob('123', JOB);
      // Do something with the returned job...
    } catch(err) {
      // Error handling...     
    }
// Get the job
try {
var job = await client.getJobByid(
    null,
    job1.id);
    // Do something with job...

    } catch(err) { // Error handling}

In the help for each class there is a general example of its use. Also one of the quality sources are the source code for the tests.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pip_services_jobs: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pip_services_jobs/pip_services_jobs.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on ios

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on linux

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on macos

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on windows

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-web on web

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime js

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Package not compatible with runtime native-aot

Because:

  • package:pip_services_jobs/pip_services_jobs.dart that imports:
  • package:pip_services_jobs/src/build/build.dart that imports:
  • package:pip_services_jobs/src/build/JobsServiceFactory.dart that imports:
  • package:pip_services_jobs/src/services/version1/JobsHttpServiceV1.dart that imports:
  • package:pip_services3_commons/pip_services3_commons.dart that imports:
  • package:pip_services3_commons/src/validate/validate.dart that imports:
  • package:pip_services3_commons/src/validate/ProjectionParamsSchema.dart that imports:
  • package:pip_services3_commons/src/validate/ArraySchema.dart that imports:
  • package:pip_services3_commons/src/reflect/ObjectReader.dart that imports:
  • package:pip_services3_commons/src/reflect/PropertyReflector.dart that imports:
  • dart:mirrors

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
angel_framework ^2.1.1 2.1.1
http ^0.12.0 0.12.1
pip_services3_commons >=1.0.5 <2.0.0 1.0.11
pip_services3_components >=1.0.2 <2.0.0 1.0.6
pip_services3_container >=1.0.0 <2.0.0 1.0.3
pip_services3_data >=1.0.0 <2.0.0 1.0.6
pip_services3_mongodb >=1.0.2 <2.0.0 1.0.4
pip_services3_rpc >=1.0.2 <2.0.0 1.0.7
Transitive dependencies
angel_container 1.1.0
angel_http_exception 1.1.0
angel_model 1.0.3
angel_route 3.1.0+1
async 2.4.2
bson 0.3.2
charcode 1.1.3
code_buffer 1.0.1
collection 1.14.13 1.15.0-nullsafety
combinator 1.1.0
convert 2.1.1
crypto 2.1.5
dart2_constant 1.0.2+dart2
file 5.2.1
fixnum 0.10.11
http2 1.0.0
http_parser 3.1.4
http_server 0.9.8+3
intl 0.16.1
logging 0.11.4
matcher 0.12.8
merge_map 1.0.2
meta 1.2.2 1.3.0-nullsafety
mime 0.9.6+3
mock_request 1.0.7
mongo_dart 0.4.0
mongo_dart_query 0.4.1
more 1.18.2 2.5.0
mustache4dart2 0.1.0
path 1.7.0
pedantic 1.9.2
pool 1.4.0
quiver 2.1.3
quiver_hashcode 2.0.0
recase 2.0.1 3.0.0
source_span 1.7.0
sprintf 4.0.2
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
tuple 1.0.3
typed_data 1.2.0 1.3.0-nullsafety
uuid 2.2.0
yaml 2.2.1
Dev dependencies
test >=1.14.2 <2.0.0