WEBINT-328-Pausas-cacelaciones #1
@@ -164,7 +164,6 @@ export class SimController {
|
||||
public suspend() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
let msgData;
|
||||
console.log("Consumiendo susension", msg)
|
||||
try {
|
||||
msgData = this.validateMsg(msg) as SimEvents.pause
|
||||
} catch (e) {
|
||||
|
||||
@@ -273,7 +273,6 @@ export class SimUseCases {
|
||||
*/
|
||||
public stage_suspend(suspendData: ActionData): () => Promise<Result<string, boolean>> {
|
||||
return async (): Promise<Result<string, boolean>> => {
|
||||
console.log("Suspend action data", suspendData)
|
||||
const correlation_id = suspendData.correlation_id
|
||||
const iccid = suspendData.identifier.identifiers
|
||||
|
||||
@@ -300,7 +299,7 @@ export class SimUseCases {
|
||||
activation_date: activationDate,
|
||||
next_check: undefined, // Que se haga instantaneamente al ser la primera
|
||||
operation_type: "suspend",
|
||||
actionData: suspendData
|
||||
actiondata: suspendData
|
||||
}
|
||||
|
||||
const taskCreated = await this.pauseRepository.addTask(newTask)
|
||||
@@ -340,7 +339,7 @@ export class SimUseCases {
|
||||
activation_date: activationDate,
|
||||
next_check: undefined, // Que se haga instantaneamente al ser la primera
|
||||
operation_type: "terminate",
|
||||
actionData: terminateData
|
||||
actiondata: terminateData
|
||||
}
|
||||
|
||||
const taskCreated = await this.pauseRepository.addTask(newTask)
|
||||
|
||||
@@ -8,7 +8,7 @@ const testTask: CreatePauseCancelTaskDTO = {
|
||||
operation_type: "suspend",
|
||||
activation_date: new Date(),
|
||||
next_check: new Date(),
|
||||
actionData: {
|
||||
actiondata: {
|
||||
dueDate: new Date().toString(),
|
||||
correlation_id: "12223",
|
||||
identifier: {
|
||||
@@ -19,20 +19,14 @@ const testTask: CreatePauseCancelTaskDTO = {
|
||||
}
|
||||
|
||||
describe("Test PauseCancelTaskRepository - DB", () => {
|
||||
function clean() {
|
||||
|
||||
}
|
||||
|
||||
const createdIds: number[] = [];
|
||||
|
||||
const pauseRepo = new PauseCancelTaskRepository(postgrClient)
|
||||
|
||||
before(() => {
|
||||
|
||||
})
|
||||
|
||||
after(() => {
|
||||
|
||||
})
|
||||
|
||||
it("Should create a task", async () => {
|
||||
@@ -66,12 +60,13 @@ describe("Test PauseCancelTaskRepository - DB", () => {
|
||||
})
|
||||
|
||||
it("Should get at least 1 pending task", async () => {
|
||||
const created = await pauseRepo.addTask(testTask)
|
||||
const pending = await pauseRepo.getPending()
|
||||
|
||||
assert.ok(pending != undefined, "A value must be returned always")
|
||||
assert.ok(pending.error == undefined, "Should not return a error")
|
||||
assert.ok(pending.data != undefined, "Data must be returned")
|
||||
|
||||
console.log("--> ", pending.data)
|
||||
console.log("--> ", pending.data[0])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -13,10 +13,10 @@ export type PauseCancelTask = {
|
||||
next_check?: Date | null;
|
||||
completed_date?: Date | null;
|
||||
error?: string | null;
|
||||
actionData: ActionData
|
||||
actiondata: ActionData
|
||||
}
|
||||
|
||||
export type CreatePauseCancelTaskDTO = Pick<PauseCancelTask, "iccid" | "activation_date" | "next_check" | "operation_type" | "actionData">
|
||||
export type CreatePauseCancelTaskDTO = Pick<PauseCancelTask, "iccid" | "activation_date" | "next_check" | "operation_type" | "actiondata">
|
||||
export type UpdatePauseCancelTaskDTO = Pick<PauseCancelTask, "id" | "next_check">
|
||||
export type FinishPauseCancelTaskDTO = Pick<PauseCancelTask, "id" | "error">
|
||||
|
||||
@@ -62,7 +62,7 @@ export class PauseCancelTaskRepository {
|
||||
RETURNING *;
|
||||
`;
|
||||
try {
|
||||
const values = [task.iccid, task.activation_date, task.next_check, task.operation_type, JSON.stringify(task.actionData)];
|
||||
const values = [task.iccid, task.activation_date, task.next_check, task.operation_type, JSON.stringify(task.actiondata)];
|
||||
const res: QueryResult<PauseCancelTask> = await this.pgClient.query(sql, values);
|
||||
return {
|
||||
data: res.rows[0]
|
||||
|
||||
@@ -81,8 +81,8 @@ async function startCron() {
|
||||
}, PERIODO_VOLCADO)
|
||||
|
||||
|
||||
//await pauseTask.run()
|
||||
const PERIODO_CANCELACIONES = 24 * 60 * 60 * 1000;
|
||||
await pauseTask.run()
|
||||
const PERIODO_CANCELACIONES = 60 * 60 * 1000;
|
||||
const clacelacionesInterval = setInterval(async () => {
|
||||
await pauseTask.run()
|
||||
}, PERIODO_CANCELACIONES)
|
||||
|
||||
@@ -6,8 +6,8 @@ import { OrderRepository } from "packages/sim-shared/infrastructure/OrderReposit
|
||||
|
||||
const logger =
|
||||
{
|
||||
log: (...data: any[]) => console.log("[i] [TaskPauseTerminate]", data),
|
||||
error: (...data: any[]) => console.error("[x] [TaskPauseTerminate] ", data),
|
||||
log: (...data: any[]) => console.log("[i] [TaskPauseTerminate]", ...data),
|
||||
error: (...data: any[]) => console.error("[x] [TaskPauseTerminate] ", ...data),
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ export class PauseTerminateTask {
|
||||
logger.error("Finalizado con errores proceso de comprobacion de lineas en pausa o canceladas")
|
||||
logger.error(err)
|
||||
}
|
||||
|
||||
const finExito = () => {
|
||||
logger.log("Finalizado con exito proceso de comprobacion de lineas en pausa o canceladas")
|
||||
}
|
||||
try {
|
||||
logger.log("Iniciando proceso de comprobacion de lineas en pausa o canceladas")
|
||||
|
||||
@@ -37,6 +41,11 @@ export class PauseTerminateTask {
|
||||
}
|
||||
|
||||
logger.log(`Se van a revisar ${peticionesRevisar.data?.length} peticiones`)
|
||||
if (peticionesRevisar.data == undefined || peticionesRevisar.data.length == 0) {
|
||||
finExito()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// 2. Se comprueba que alguna de las lineas haya dejado de estar en estado de test
|
||||
const iccids = peticionesRevisar.data.map(e => e.iccid)
|
||||
@@ -68,6 +77,8 @@ export class PauseTerminateTask {
|
||||
lines = await lineGenerator.next()
|
||||
}
|
||||
|
||||
console.log("Cargado: ", lineasActualizadas)
|
||||
|
||||
// 3. Se separan las lineas que se tienen que actualizar al no ser test
|
||||
// y las que se tienen que reencolar al ser test
|
||||
const lineasNoTest = lineasActualizadas.filter(e => e.status.billingStatus != "TEST")
|
||||
@@ -101,53 +112,74 @@ export class PauseTerminateTask {
|
||||
dueDate.setMinutes(new Date().getMinutes() + 15)
|
||||
|
||||
const operacionTipo = operacion.operation_type
|
||||
const actionData = operacion.actionData
|
||||
const correlation_id = operacion.actionData.correlation_id
|
||||
actionData.dueDate = dueDate.toString()
|
||||
const actionData = operacion.actiondata
|
||||
const correlation_id = operacion.actiondata.correlation_id
|
||||
actionData.dueDate = dueDate.toISOString()
|
||||
|
||||
if (linea.status.billingStatus == "ACTIVATED") {
|
||||
let exito = false;
|
||||
let result = null;
|
||||
// IMPORTANTE COMRPOBAR EL DUE DATE
|
||||
switch (operacionTipo) {
|
||||
case "suspend":
|
||||
result = await this.simUsecases.suspend(actionData)()
|
||||
break;
|
||||
case "terminate":
|
||||
result = await this.simUsecases.terminate(actionData)()
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (linea.status.billingStatus) {
|
||||
case "ACTIVATED":
|
||||
let exito = false;
|
||||
let result = null;
|
||||
// IMPORTANTE COMRPOBAR EL DUE DATE
|
||||
switch (operacionTipo) {
|
||||
case "suspend":
|
||||
result = await this.simUsecases.suspend(actionData)()
|
||||
break;
|
||||
case "terminate":
|
||||
result = await this.simUsecases.terminate(actionData)()
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == undefined) {
|
||||
logger.error("Operacion desconocida", operacion)
|
||||
} else if (result?.error != undefined) {
|
||||
// error usecase
|
||||
logger.error(result.error)
|
||||
if (result == undefined) {
|
||||
logger.error("Operacion desconocida", operacion)
|
||||
} else if (result?.error != undefined) {
|
||||
// error usecase
|
||||
logger.error(result.error)
|
||||
await this.pauseRepo.finishTask({
|
||||
id: operacion.id,
|
||||
error: result.error
|
||||
})
|
||||
if (correlation_id != undefined)
|
||||
await this.orderRepo.errorOrder({
|
||||
correlation_id: correlation_id,
|
||||
status: "dlx",
|
||||
reason: result.error
|
||||
})
|
||||
} else {
|
||||
// ok
|
||||
await this.pauseRepo.finishTask({ id: operacion.id })
|
||||
if (correlation_id != undefined)
|
||||
await this.orderRepo.finishOrder({ correlation_id })
|
||||
}
|
||||
|
||||
break;
|
||||
case "CANCELED":
|
||||
await this.pauseRepo.finishTask({
|
||||
id: operacion.id,
|
||||
error: result.error
|
||||
error: "billingStatus is CANCELED"
|
||||
})
|
||||
if (correlation_id != undefined)
|
||||
await this.orderRepo.errorOrder({
|
||||
correlation_id: correlation_id,
|
||||
status: "dlx",
|
||||
reason: result.error
|
||||
})
|
||||
} else {
|
||||
// ok
|
||||
await this.pauseRepo.finishTask({ id: operacion.id })
|
||||
await this.orderRepo.finishOrder({ correlation_id })
|
||||
break;
|
||||
case "SUSPENDED":
|
||||
await this.pauseRepo.finishTask({
|
||||
id: operacion.id,
|
||||
error: "billingStatus is SUSPENDED"
|
||||
})
|
||||
if (correlation_id != undefined)
|
||||
await this.orderRepo.finishOrder({ correlation_id })
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "TEST":
|
||||
// No puede ser
|
||||
default:
|
||||
logger.error("billingStatus desconocido", linea.status.billingStatus)
|
||||
|
||||
// TODO: SUSPENDED Y TERMINATED
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
logger.log("Finalizado con exito proceso de comprobacion de lineas en pausa o canceladas")
|
||||
finExito()
|
||||
} catch (e) {
|
||||
finError(e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user