TL Cron Job
Functionality:
To send reminder messages one week prior to licenses which are expiring
To expire licenses which have passed there validity
Configuration:
BusinessService:
EXPIRE action is added on APPROVED state which takes the application to new state called EXPIRED. The following are json’s to be added in current businessService:
Action JSON :
{
"action": "EXPIRE",
"nextState": "EXPIRED",
"roles": [
"SYSTEM"
]
}
State JSON:
{
"sla": null,
"state": "EXPIRED",
"applicationStatus": "EXPIRED",
"docUploadRequired": false,
"isStartState": false,
"isTerminateState": true,
"isStateUpdatable": false
}
To update the businessService first search the businessService and then add the above json’s in the search response and then call update on the resulting businessService. ( Action json has to be added inside actions array of APPROVED state and state json can be directly added in states array of businessServices)
MDMS:
MDMS config with name CronJobAPIConfig.json
is added in common master. This config contains the API endpoints which has to be called by the cron job.
{
"tenantId": "pb",
"moduleName": "common-masters",
"CronJobAPIConfig": [
{
"jobName": "daily",
"active": "true",
"method": "POST",
"url": "http://tl-services.egov:8080/tl-services/v1/TL/Expiry/_batch",
"payload": {
"RequestInfo": "{DEFAULT_REQUESTINFO}"
},
"header": {
"Content-Type": "application/json"
}
},
{
"jobName": "daily",
"active": "true",
"method": "POST",
"url": "http://tl-services.egov:8080/tl-services/v1/TL/Reminder/_batch",
"payload": {
"RequestInfo": "{DEFAULT_REQUESTINFO}"
},
"header": {
"Content-Type": "application/json"
}
}
]
}
Active flag can be used to enable or disable particular entry while jobName specifies which cron job will call that endpoint. The placeholder {DEFAULT_REQUESTINFO}
can be used for default RequestInfo. The placeholder will be replaced with RequestInfo containing the userInfo of SYSTEM user with userName CRONJOB.
System User:
If the placeholder {DEFAULT_REQUESTINFO}
is used a user has to be created with role and type SYSTEM and userName CRONJOB. Please Note, the created user must be active. Following is a sample create request:
curl --location --request POST 'https://egov-micro-dev.egovernments.org/user/users/_createnovalidate' \
--header 'Content-Type: application/json' \
--data-raw '{
"requestInfo": {
"apiId": "Rainmaker",
"ver": ".01",
"ts": null,
"action": "_update",
"did": "1",
"key": "",
"msgId": "20170310130900|en_IN",
"authToken": "5eb3655f-31b1-4cd5-b8c2-4f9c033510d4"
},
"user": {
"userName": "CRONJOB",
"name": "System cron job",
"gender": null,
"mobileNumber": "9191919191",
"type": "SYSTEM",
"roles": [
{
"id": null,
"name": "System user",
"code": "SYSTEM",
"description": null,
"createdBy": null,
"createdDate": null,
"lastModifiedBy": null,
"lastModifiedDate": null,
"tenantId": null
}
],
"tenantId": "pb"
}
}'
If the user service build running on current environment encrypts PIIs while storing DB records then in “DataSecurity” module and “DecryptionABAC“ master of mdms ex:- https://github.com/egovernments/egov-mdms-data/blob/master/data/pb/DataSecurity/DecryptionABAC.json In “ALL_ACCESS“ section add following values in “roleAttributeAccessList“.
{
"roleCode": "SYSTEM",
"attributeAccessList": [
{
"attribute": {
"jsonPath": "*/name"
},
"accessType": "PLAIN"
},
{
"attribute": {
"jsonPath": "*/mobileNumber"
},
"accessType": "PLAIN"
}
]
}
Kubernetes:
The following is the kubernetes configuration for the cron job:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: daily
spec:
schedule: "1 0 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: daily
image: talele08/api-cronjob-image-4
command: ["python3","cronJobAPIConfig.py"]
args: ["daily"]
env:
- name: JOB_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
restartPolicy: OnFailure
The cron job timing can be adjusted using the schedule
property. The above value schedule: "1 0 * * *"
will trigger the cron job everyday at 00:01 AM.
To create the cron job the following command can be used:
kubectl create -f FILE_PATH
The cron job can be deleted by:
kubectl delete cronjob JOB_NAME
The above configurations, dockerfile and the python script to be called by cron job are uploaded in the link described below:
https://github.com/egovernments/utilities/tree/API_CRON/egov-api-cron-job
Localization:
Following is the message cURL to be pushed in localization:
{
"RequestInfo": {
"apiId": "Rainmaker",
"ver": ".01",
"ts": "",
"action": "_create",
"did": "1",
"key": "",
"msgId": "20170310130900|en_IN",
"authToken": "{{qaAuth}}"
},
"tenantId": "pb",
"module": "rainmaker-tl",
"locale": "en_IN",
"messages":[
{
"code": "tl.en.reminder",
"message": "Dear {OWNER_NAME}, Your trade license number {LICENSE_NUMBER} for {TRADE_NAME} is expiring on {EXPIRY_DATE}. Please Renew your Trade License to avoid any penalties.",
"module": "rainmaker-tl",
"locale": "en_IN"
}
]
}
Builds:
tl-services and egov-workflow-v2 needs to be promoted.