Statusek
Universal tool for reading & saving statuses of task, documents & other
General
Main concept
It's a service has given functionality to manage statuses across different services or systems
Service defines contract of status model some one object (for example, task or document)
Imagine, we have the chain of two application:
Service1 -> Service2
Workflow between them looks like (async interaction):
- Service1 push task to Service2
- Service2 executes task and writes back statuses of execution
- Service1 see statuses and waits when task will be fully executed
Conclusions:
- We should develop status model
- We should develop methods to set statuses
- We should develop method to share statuses
- Service2 can change statuses it retuns and does not inform Service1 about this
- We should foresee when task is hold on Service2 (timed out) and finish status never will be returned
Statusek realizes all of these points.
Statusek has three restAPI methods for organize interaction between services:
- instance/create - create instance (process) of some object (model) and get its token
- status/setStatus - set status of instance (by instance token & status name)
- status/checkStatusIsSet - check certain status is set
- instance/checkIsFinished - checks instance is finished or not
- event/getEvents - gets all setted statuses
So, interaction is changing to:
- Service1 calls instance/create and gets instanceToken
- Service1 push task to Service2 and transmit instanceToken to it
- Service2 executes task and writes certain statuses by call status/setStatus
- Service1 call instance/checkIsFinished and understands when task will be fully executed
- If Service2 hasn't returned any of its statuses then instance/checkIsFinished is set to True
Statuses
Statuses represents states some process, action or object.
Rest API
Creating instance of process
First, service-initiator of process creates instance of process inside SMS (statuses management service)
It call:
http://hostname:8080/instance/create
with raw json in the body:
{
"object_name":"2-POINT LINE TASK",
"instance_timeout":600
}
and get something like this:
{
"instance_token": "1d36bcdf-d776-4e7a-97a6-4431079d2b2e",
"message": "Success",
"status": true
}
Setting statuses
Services, who knows token of instance (process) can set statuses by calling:
http://hostname:8080/status/setStatus
with raw json in the body:
{
"instance_token":"1d36bcdf-d776-4e7a-97a6-4431079d2b2e",
"status_name": "RUN"
}
and get something like this:
{
"message": "Success",
"status": true
}
or status: false and message with error text
Check some status is set
For specific logic we can to want check some status was set or not
We call:
http://hostname:8080/status/checkStatusIsSet
with raw json in the body:
{
"instance_token":"1d36bcdf-d776-4e7a-97a6-4431079d2b2e",
"status_name": "FINISHED"
}
and get something like this:
{
"message": "Status is not set",
"status": false
}
or status: true if checked status is set
Checking process is finished
Service-initiator want to know process is finished yet or not
We call:
http://hostname:8080/instance/checkIsFinished
with raw json in the body:
{
"instance_token":"1d36bcdf-d776-4e7a-97a6-4431079d2b2e"
}
and get something like this:
{
"message": "Instance is finished",
"status": true
}
or status: false and message: Instance is not finished
Getting all statuses of process
We call:
http://hostname:8080/event/getEvents
with raw json in the body:
{
"instance_token":"1d36bcdf-d776-4e7a-97a6-4431079d2b2e"
}
and get something like this:
{
"events": [
{
"Status": {
"ObjectID": 2,
"StatusID": 2,
"StatusName": "RUN",
"StatusDesc": "Task is running",
"StatusType": "MANDATORY"
},
"EventCreationDt": "2020-06-15T02:22:05.38288+03:00"
},
{
"Status": {
"ObjectID": 2,
"StatusID": 3,
"StatusName": "FINISHED",
"StatusDesc": "Task is finished",
"StatusType": "MANDATORY"
},
"EventCreationDt": "2020-06-15T02:22:08.998913+03:00"
}
],
"message": "Success",
"status": true
}