417 Commits

Author SHA1 Message Date
8666499626 Merge remote-tracking branch 'origin/feature/cierres' into feature/cierres 2025-07-12 09:43:19 -04:00
f752256f76 Fcgi idle timeout 2025-07-12 09:43:02 -04:00
6dda5aef00 Habilitar sync 2025-07-03 17:30:58 -04:00
18e79b76d6 Better logging 2025-07-03 17:17:55 -04:00
239376fadc Send all 2025-07-03 17:13:22 -04:00
15ba23bf23 Toku update output 2025-07-03 17:06:00 -04:00
73328240cc Update invoices 2025-07-03 17:00:01 -04:00
495581de8f Update subscriptions 2025-07-03 16:59:41 -04:00
cb0731b67d Update subscriptions 2025-07-03 16:37:57 -04:00
4980839568 Merge remote-tracking branch 'origin/feature/cierres' into feature/cierres 2025-07-01 17:16:39 -04:00
7714e25270 Uso de cuenta al agregar y editar para Toku 2025-07-01 17:14:53 -04:00
8a043b21bc Migracion para guardar account-key de toku 2025-07-01 17:14:21 -04:00
925faeb6f4 Migracion para guardar account-key de toku 2025-07-01 15:28:07 -04:00
f11b7dcd9b PHP more request handlers 2025-06-30 17:25:48 -04:00
e35053edce FastCGI Command max requests 2025-06-30 17:09:45 -04:00
829ab86770 FastCGI pool 2025-06-30 16:39:55 -04:00
4b66694166 Batch queue 2025-06-30 15:52:36 -04:00
d4f8804fbb Batch queue 2025-06-30 15:52:28 -04:00
5f4d8a4bc2 FIX: separate details exception 2025-06-30 11:47:57 -04:00
1fa152c07f FIX: new line exception.log 2025-06-30 11:44:05 -04:00
7f8bd607e3 Job retries 2025-06-27 18:42:47 -04:00
1bbee1121b FIX: Authorization en FastCGI 2025-06-27 18:00:45 -04:00
352e33179c More detail 2025-06-27 17:42:09 -04:00
f34d7338f1 FIX: FasCGI Response 2025-06-27 17:35:17 -04:00
4dd83ae63d FIX: Error observado 2025-06-27 17:24:04 -04:00
e265854958 FIX: Error observado 2025-06-27 17:21:25 -04:00
174b29efff FIX: str_starts_with 2025-06-27 17:17:21 -04:00
1c0f4a5ae9 Try to register fatal errors in file 2025-06-27 17:17:06 -04:00
ccee5f9f56 FIX: more details 2025-06-27 16:58:15 -04:00
9677f11aef FIX: seguir cuando existe error. 2025-06-27 16:56:24 -04:00
c21de2848d FIX: saltarse lineas comentadas 2025-06-27 16:51:16 -04:00
348bb18654 LoggerEnabled Fix 2025-06-25 18:14:43 -04:00
a2a9f4bbb4 LoggerEnabled Fix 2025-06-25 18:11:28 -04:00
ab7328b40b FastCGI 2025-06-25 18:07:08 -04:00
7f97862324 Revisiones 2025-06-25 12:41:28 -04:00
9edf0d9120 Revisiones 2025-06-25 12:22:01 -04:00
ca1ed3f870 Pruebas de integracion con seeds 2025-06-24 21:55:02 -04:00
360537c638 Prueba de integracion para service worker 2025-06-24 14:24:47 -04:00
a6e6b8acc0 Prueba de integracion para service worker 2025-06-24 12:56:03 -04:00
a4e2b4fc7a Seed TipoEstadoPago 2025-06-24 12:55:46 -04:00
479047cd6a Dependencias para testeo 2025-06-24 12:55:02 -04:00
29d9ea8e4a Correr seeds y botar tablas al final 2025-06-24 12:54:48 -04:00
a7cd661938 Registro de worker 2025-06-24 12:54:32 -04:00
7bdcc7168a Container separado a archivo a parte para poder cargarlo en otros lados 2025-06-24 12:54:19 -04:00
d2dff57531 FIX: id de migracion 2025-06-24 12:53:56 -04:00
39198bbe7c get Uf asincronico 2025-06-24 11:20:53 -04:00
200510d60a Prueba Service Worker 2025-06-24 11:20:21 -04:00
ecc67a43c8 Service Worker, corre metodos de servicios asincronicamente, requiere parametros escalares y no retornar mas que bool o void 2025-06-24 11:19:58 -04:00
64791d1fc5 Alias enqueue 2025-06-24 11:16:29 -04:00
4053854410 Prueba UF 2025-06-24 11:16:19 -04:00
a687743762 FIX: No buscar UF para fechas mayores a hoy o día nueve del mes 2025-06-24 11:04:33 -04:00
38fb6f3bcc Pausa a external 2025-06-19 16:47:24 -04:00
1e6bac61b5 FIX: Limpiar archivos 2025-06-19 16:47:06 -04:00
a611ae247d FIX: prorrateo ingresado en valor % 2025-06-12 11:28:04 -04:00
c02c6eb15c FIX: Add custom HttpException 2025-06-10 19:36:56 -04:00
b7e0217cf3 FIX: remove ext-http 2025-06-10 19:35:17 -04:00
2fd1a44984 FIX: install ext-http with external script 2025-06-10 19:04:32 -04:00
fe912db62b Add ext-http 2025-06-10 18:20:05 -04:00
da90160a2a Add ext-http 2025-06-10 18:02:05 -04:00
64047ef577 TOKU: FIX: exceptions 2025-06-10 17:48:36 -04:00
feef90afd6 TOKU: payments loop through pages 2025-06-10 17:46:16 -04:00
32e1e49a97 FIX: cuerpo para borrar payments 2025-06-10 17:34:04 -04:00
11c64cb10f FIX: url para borrar 2025-06-10 17:29:39 -04:00
823f97ce5f FIX: log levels 2025-06-10 17:24:38 -04:00
4ae72199fc Better external logging 2025-06-10 17:00:20 -04:00
d841b1aeed FIX: url de payments en Toku 2025-06-10 16:57:34 -04:00
666cac1958 FIX: url de payments en Toku 2025-06-10 16:54:46 -04:00
71c189e236 FIX: circular dependency 2025-06-10 16:49:34 -04:00
5b6a1c42e3 Toku: reorden 2025-06-10 16:28:46 -04:00
81bce6fe7f Cleanup 2025-06-10 16:28:13 -04:00
e1072ea252 Toku: Reset payments 2025-06-10 16:26:33 -04:00
21473fe52c Valor cuota en CLP 2025-06-10 15:27:09 -04:00
7d589e0e87 Valor cuota en CLF 2025-06-10 15:24:51 -04:00
c48a0d2381 Valor cuota en CLP 2025-06-10 15:14:25 -04:00
abb1ce7299 Mas logging 2025-06-09 12:44:42 -04:00
f1ed9668fc email -> mail 2025-06-06 18:25:12 -04:00
f9ae809fc4 Data too large 2025-06-06 18:10:59 -04:00
06e5292af1 Log add response 2025-06-06 18:10:06 -04:00
47ba664142 Log customer params 2025-06-06 18:04:57 -04:00
d10ee33215 better format for mysql 2025-06-06 17:55:58 -04:00
5134630525 Correct Exceptions 2025-06-06 17:37:42 -04:00
13b246b998 Merge remote-tracking branch 'origin/feature/cierres' into feature/cierres 2025-06-06 17:11:33 -04:00
d601d7d719 Mas logs y middlewares en Guzzle 2025-06-06 17:11:22 -04:00
dc0ae2746b FIX: Correct HMAC validation 2025-06-03 23:07:47 -04:00
eb402b1b71 FIX: notice logs 2025-06-03 23:07:08 -04:00
c5188a1feb HMAC not static 2025-06-03 23:04:57 -04:00
1c3052219c Debug 2025-06-03 22:59:49 -04:00
9e8a388653 Debug 2025-06-03 22:59:03 -04:00
cbee830f7a Debug 2025-06-03 22:55:35 -04:00
d5b8c7f877 FIX: JSON_SEARCH 2025-06-03 22:51:26 -04:00
b668844fea Debug 2025-06-03 22:29:13 -04:00
f2169c9536 FIX: fetch all values in column 2025-06-03 22:27:15 -04:00
48bcb33bad FIX: event_types -> events 2025-06-03 22:24:09 -04:00
92ae0b4ac2 FIX: Missing connection 2025-06-03 22:22:33 -04:00
44540d0dc3 Validated external query log 2025-06-03 22:19:11 -04:00
d9a2f63691 Use webhook secrets to validate 2025-06-03 22:11:57 -04:00
b10accf602 Store webhooks 2025-06-03 22:01:03 -04:00
981858f251 HMAC implementation for signature validation 2025-06-03 21:53:49 -04:00
8c0bd450ef FIX: delete url 2025-06-03 21:26:10 -04:00
8996765cb4 FIX: maxLogLevel 2025-06-03 21:16:44 -04:00
ec2451cb69 FIX: maxLogLevel 2025-06-03 21:12:43 -04:00
37d30d2aec Cleanup logs 2025-06-03 21:09:13 -04:00
afb6e2526f FIX: Timezone cli 2025-06-03 20:14:15 -04:00
a9b6f2a87b FIX: Error code for missing TOKU_ENV 2025-06-03 19:58:36 -04:00
9aeb6906f6 Debug 2025-06-03 19:43:46 -04:00
879d365baf Not needed 2025-06-03 19:42:23 -04:00
1d03b262ae Debug 2025-06-03 19:35:36 -04:00
2c175c8171 Detailed login errors 2025-06-03 19:20:55 -04:00
a750bdbfaa Detailed login errors 2025-06-03 19:20:44 -04:00
7f6d0232c0 Cleanup files 2025-06-03 19:20:09 -04:00
37cff67a1c Log reseteando 2025-06-03 17:06:39 -04:00
bc3d739af9 Cleanup 2025-06-03 16:52:01 -04:00
46efbb57c1 Log body de reset 2025-06-03 16:25:07 -04:00
d71333b334 Queue cada 2 minutos 2025-06-03 16:13:04 -04:00
688b500f1e Parametros correctos 2025-06-03 16:06:14 -04:00
d4b1a66a9e FIX: ventas_ids vacios 2025-06-03 16:02:04 -04:00
e796d91d95 Si token no existe, no se puede borrar 2025-06-03 16:01:48 -04:00
2a442417ce FIX: Loop frequency 2025-06-03 13:01:40 -04:00
3c161ed4e9 Loop frequency 2025-06-03 12:58:57 -04:00
3c8822e531 FIX: Log job requests 2025-06-03 12:46:47 -04:00
b3b91d3f8f Log job requests 2025-06-03 12:45:36 -04:00
6e34a76a3f FIX: Request log processor no funciona 2025-06-03 12:34:08 -04:00
ed29dfb984 Request Log Processor 2025-06-03 12:17:52 -04:00
7f37dc76e3 Log forbidden 2025-06-03 12:06:35 -04:00
a62293e509 Mejora en separacion 2025-06-03 12:06:02 -04:00
fbfc2cb8ae Cambios de usos de env vars 2025-06-03 12:04:53 -04:00
02665ac6bd Extras ya enviados por processor 2025-06-03 11:52:31 -04:00
300d966f3f Separation of logs in cli 2025-06-03 11:49:03 -04:00
27031035ed Filtro en server params faltante 2025-06-03 11:45:36 -04:00
18fc9a76fd Filtro en server params 2025-06-03 11:37:14 -04:00
cb6fa73a21 FIX: Recargar proyectos si no se encuentra proyecto_id, si aun no existe retornar 0 2025-06-03 10:35:07 -04:00
8796762cfe Mas datos en el registro de accessos 2025-06-03 10:24:54 -04:00
99c9952c93 Mas datos en el registro de logins. 2025-06-03 10:22:52 -04:00
9895fd6a70 FIX: Mas registro de login desde cli 2025-06-02 18:45:11 -04:00
c1149d89be FIX: Cleanup after create, but before initialized query. 2025-06-02 18:03:43 -04:00
7d8e2249de FIX: Detalle en logging. 2025-06-02 17:58:24 -04:00
a54586e870 FIX: valor cuota cuando UF no existe. 2025-05-30 17:10:59 -04:00
734f258382 Validar con headers 2025-05-30 14:18:48 -04:00
f728ed0b55 FIX: Log de envio 2025-05-30 12:48:12 -04:00
6144accb8e FIX: Toku envía complejo el header 2025-05-29 19:56:43 -04:00
f399eb8d47 Validate with service 2025-05-29 19:43:06 -04:00
b4159d1417 Log external tries 2025-05-29 19:24:35 -04:00
2a792a947d More granular control of external validation configuration 2025-05-29 19:22:55 -04:00
25710d616a Registro de success entrantes 2025-05-29 19:15:17 -04:00
3197802264 Cleanup 2025-05-29 19:10:09 -04:00
6c53127c2f Body json 2025-05-29 19:06:54 -04:00
b7391a77d3 DEBUG: body 2025-05-29 17:44:30 -04:00
5b499aee75 Content-type 2025-05-29 17:43:14 -04:00
4505531c5f Output body 2025-05-29 17:42:21 -04:00
3f8adc753c Add body to Enqueue command 2025-05-29 17:40:45 -04:00
ace205798f FIX: Manejo de Errores en Ventas 2025-05-29 16:02:13 -04:00
6e0e1fc75e Parametros faltantes 2025-05-27 19:30:08 -04:00
026474c63c Enqueue ventas para enviar a Toku 2025-05-27 19:24:23 -04:00
f32204df97 FIX: Remove toku concept in database 2025-05-27 18:35:06 -04:00
2852816eae FIX: Parametros extra para Toku 2025-05-27 18:27:37 -04:00
892cdf324f Comando para resetear Toku 2025-05-27 18:17:56 -04:00
a9a10e012d Uso de external Logger para los servicios External 2025-05-27 16:28:34 -04:00
b7089f7a1c Timezone por DI 2025-05-27 16:19:47 -04:00
aed26cfcd8 FIX: Estado cuota abono 2025-05-23 12:15:51 -04:00
896dded6eb Apellido materno en blanco 2025-05-23 12:12:34 -04:00
3b03c4b64b Logging 2025-05-19 16:06:44 -04:00
f34ed03b84 Logging 2025-05-19 14:02:55 -04:00
ce75ec1548 External logs
FIX: Ofuscator
2025-05-19 13:55:59 -04:00
312baa34f6 Access Logs 2025-05-19 13:14:13 -04:00
b7c5e4ebc3 Opcion de enviar update a los servicios externos 2025-05-16 19:14:20 -04:00
105179b4ed Fixes de telefono y apellido de persona 2025-05-16 16:35:17 -04:00
16cd29635d Zona horaria en cli 2025-05-16 14:47:31 -04:00
2bdb2a0ed0 Uso de zona horaria en output de comandos 2025-05-16 14:44:48 -04:00
8ce7d2570d FIX: Check if invoice exists before sending, if exists then save
Send correct UF amount if date in future
2025-05-16 14:36:20 -04:00
8ba54fd3ad Queue command with direct redis access so it's faster 2025-05-16 13:56:32 -04:00
f47f86dd2b BaseLoop different logger 2025-05-16 12:54:52 -04:00
8ca68bf7e8 Crontab para revisar servicios externos 1 vez al dia 2025-05-15 19:33:53 -04:00
8965354528 Cambio en queue para que no quede pegado esperando respuesta en cli.
Chequeo de servicios externos para agregar elementos pendientes.
2025-05-15 19:32:25 -04:00
8d32aecd09 Zona horaria en logs 2025-05-15 16:07:29 -04:00
c8f79e076e Envio de datos editados de Propietario 2025-05-15 16:05:55 -04:00
9e0d604d79 Respuesta 200 a webhook de Toku 2025-05-15 16:05:03 -04:00
331d004040 Eliminar script::type 2025-05-15 16:04:35 -04:00
03317b3aa5 Agregar datos propietario 2025-05-15 15:23:34 -04:00
e33edc4d7b FIX: proyectos minuto 0 de cada hora, en vez de cada minuto de esa hora 2025-05-15 12:08:33 -04:00
bb459a2ff5 FIX: proxy no identificado por web 2025-05-15 11:47:28 -04:00
5e2d2e861f Logs no pasan desbordan de nivel 2025-05-15 10:53:59 -04:00
e9b2fe9963 FIX: monto enviado en UF 2025-05-15 10:12:34 -04:00
2f481ef8a9 FIX: mapeo de datos al actualizar pago 2025-05-15 10:06:35 -04:00
386fe452af Catch error 2025-05-15 10:06:00 -04:00
91ad1e39f8 Endpoint para la prueba 2025-05-14 12:41:59 -04:00
a3a5b58cfb Correctos parametros 2025-05-13 20:19:03 -04:00
1d77d65af2 Ventas con cuotas pendientes 2025-05-13 20:18:51 -04:00
0f0c81e283 Uso de request en queue 2025-05-13 20:18:40 -04:00
ac278ca690 Parametros correctos para persona. 2025-05-13 20:18:20 -04:00
97d34f9ad6 Uso de request original 2025-05-13 20:18:09 -04:00
134588c96d Envio de estado de cuotas. 2025-05-13 20:17:53 -04:00
8b6516241d Manejo de contenido 2025-05-13 20:13:15 -04:00
d6e60efcaf Parametros correctos 2025-05-13 20:12:26 -04:00
3e937ab748 Fetch ventas con cuotas pendientes 2025-05-13 20:11:49 -04:00
fa6881d0a9 Formato correcto de fecha y bool 2025-05-13 20:11:02 -04:00
f07c1f1cbd Formato correcto de fecha 2025-05-13 20:10:46 -04:00
148d08089d Estado Cuota y Pago 2025-05-13 20:10:24 -04:00
45b6ee710e Job mas completo 2025-05-13 20:10:12 -04:00
c84277fdc4 Update services 2025-05-13 20:09:50 -04:00
c0024a4a63 Parse body correctly and test fill 2025-05-13 20:03:20 -04:00
308a84a448 Send current request to queue for parameters 2025-05-13 20:02:50 -04:00
91c74bf113 Min log level 2025-05-13 16:17:47 -04:00
024a6eae54 Jobs not being updated 2025-05-13 16:06:09 -04:00
d536342425 No output on wait 2025-05-13 15:58:49 -04:00
e7f3b33850 Wait till next minute after running jobs 2025-05-13 15:53:13 -04:00
c47d94d475 FIX: missing use 2025-05-13 15:49:41 -04:00
ee74fc7588 FIX: esperar al siguiente minuto 2025-05-13 15:47:18 -04:00
5ac324de6a Hora en output 2025-05-13 15:40:32 -04:00
dfb0ff7aea Missing middlewares 2025-05-13 15:16:29 -04:00
6d1a1c914a Wait for execution 2025-05-13 15:15:20 -04:00
b45d03aa7e Reestructura APIClient 2025-05-13 09:32:48 -04:00
4e0b611bcf FIX: Mayuscula 2025-05-13 09:31:51 -04:00
20ea5d021d FIX: missing text 2025-05-12 19:58:20 -04:00
32dc24a783 Newline 2025-05-12 19:54:03 -04:00
95a6aa96e9 Queue 2025-05-12 19:46:31 -04:00
f14cdd2730 Updates 2025-05-12 19:46:09 -04:00
3006adb0f7 Configuracion servicios 2025-05-12 19:44:58 -04:00
d22480dcb8 User edit and delete 2025-05-12 19:44:16 -04:00
425b85e40d Unify cli logs 2025-05-12 19:44:00 -04:00
2c21e48562 FIX: DEPRECATED 2025-05-12 19:43:39 -04:00
8d3ce99be7 Update env sample 2025-05-12 18:32:30 -04:00
35386724b3 FIX: DEPRECATED 2025-05-12 18:07:14 -04:00
1597657f0e FIX: Toku external 2025-05-12 16:35:33 -04:00
c6bbaf3404 FIX: DEPRECATED 2025-05-12 16:08:10 -04:00
9e2d7277b0 Validacion API/external 2025-05-12 16:01:09 -04:00
abe37227ce API/external 2025-05-12 15:47:51 -04:00
32130f0bc2 Usando variables definidas 2025-05-12 14:04:58 -04:00
d78bdaa7f5 Falta ortografia 2025-05-12 13:57:43 -04:00
1266c3859d Migration for Jobs 2025-05-12 13:54:28 -04:00
c5466b2c4d Ignore optionals 2025-05-12 13:15:22 -04:00
6d8e8a9068 Env sample update 2025-05-12 13:06:44 -04:00
4d5b657b92 Manejo de trabajos en cli por php en vez de cron 2025-05-10 12:40:06 -04:00
4ca1616dfc Integracion Toku a flujo 2025-05-10 12:39:31 -04:00
fb7177fd65 Reorden Toku 2025-05-10 12:38:14 -04:00
1486d6cf38 Toku settings 2025-05-10 12:32:01 -04:00
8b2de31e02 Job Queue 2025-05-10 12:30:35 -04:00
61324f159b Toku endpoint 2025-05-10 12:30:21 -04:00
c95e74d574 Controlador Toku 2025-05-09 18:31:00 -04:00
59ecb6cc79 Se agregan fetchs 2025-05-09 18:05:40 -04:00
db84187461 Pruebas de Toku 2025-05-09 18:05:19 -04:00
c2f98c8b0d Excepcion 2025-05-09 18:04:37 -04:00
8d73987ac3 FIX: Cambios a Servicios Toku 2025-05-09 18:04:17 -04:00
400b2754bf FIX: Totales para multipropietario no sumaban correctamente 2025-05-09 13:33:08 -04:00
418becaeda FIX: onChange 2025-05-08 18:15:32 -04:00
679b401101 Servicio Toku para enviar datos 2025-05-08 17:17:49 -04:00
26b6862955 FIX: prueba Servicio Customer 2025-05-08 17:17:24 -04:00
e239669839 FIX: prueba modelo Customer 2025-05-08 17:16:55 -04:00
adc0e52c1e Fix: estructura interface 2025-05-08 17:16:32 -04:00
d1905194bd rut en Customer en formato Toku 2025-05-08 17:16:03 -04:00
a5c1d60819 Servicios para Toku 2025-05-08 16:17:26 -04:00
5ad4fc4038 Tests de Repositories 2025-05-08 16:17:14 -04:00
ca5354a3ee Cambio en namespace 2025-05-08 11:13:23 -04:00
c1ebac6c0c Pruebas de repositories 2025-05-08 11:13:06 -04:00
f742c7ddd0 Pruebas de modelos 2025-05-08 10:45:31 -04:00
5d5f9866bb Modelos para Toku 2025-05-07 20:05:00 -04:00
0866292d84 Migraciones para guardar datos de Toku 2025-05-07 20:04:27 -04:00
e02ed4684f LoggerAwareInterface abstract 2025-05-07 20:04:06 -04:00
8be5f94b7c Log solo los errores fatales. 2025-05-07 20:01:55 -04:00
878b02ee52 SII falla si fecha está en el futuro. 2025-05-07 19:42:39 -04:00
f3e15b34a8 Persona conectada con Propietario 2025-05-07 19:24:33 -04:00
3903551176 FIX: migraciones fallando 2025-05-07 19:23:37 -04:00
43eb8ec758 FIX: no borra todo 2025-05-07 19:22:39 -04:00
a405b15410 Uso de script central de Rut 2025-05-06 10:00:12 -04:00
a2f2d94e64 Docker image con tag 2025-05-06 09:47:54 -04:00
0587b64d65 Docker image 2025-05-06 09:37:23 -04:00
a6b81f1bff FIX: Not needed 2025-05-06 09:15:46 -04:00
4239bafc26 FIX: echo append 2025-05-05 19:33:46 -04:00
6591e9f80e FIX: debian ftp 2025-05-05 19:33:01 -04:00
b57f32c86b FIX: Circular dependency 2025-05-05 19:10:31 -04:00
0e903f99c4 FIX: Circular dependency 2025-05-05 19:08:44 -04:00
186cd0f5b8 Reparaciones con Prueba 2025-05-05 19:01:15 -04:00
167d8e1ab7 PHP Dom en PHP 8.4 2025-05-05 19:00:41 -04:00
46802507a7 SII como provider de UF 2025-05-05 18:16:18 -04:00
aaf2ed7612 UF service en Venta 2025-05-05 18:15:48 -04:00
3ced9e40b1 const en Money y multi provider 2025-05-05 18:15:29 -04:00
594cb68b09 Provider SII 2025-05-05 18:14:50 -04:00
af68c4b8ec Ine null date 2025-05-05 18:14:20 -04:00
ea8f483dd5 FIX: Repository UF 2025-05-05 18:13:55 -04:00
5f53c77a1f Repository::getConnection 2025-05-05 18:13:12 -04:00
b9adb9108b Provider null date 2025-05-05 18:12:58 -04:00
8be085222a Not Allowed template 2025-05-05 16:46:41 -04:00
d1e4314b35 Valor de UF de hoy cuando no se encuentra valor. 2025-05-05 16:46:14 -04:00
7d04b406ab Grabar UF y capacidad de obtener hoy. 2025-05-05 16:45:43 -04:00
972e57b6f1 Mejora en respuesta cuando no existe algun valor. 2025-05-05 16:43:24 -04:00
5f63bdbf4a Fecha maxima de venta es hoy 2025-05-05 16:41:08 -04:00
a8325c3310 Uso de NumberInput en Edit BonoPie 2025-05-05 15:55:23 -04:00
7e54b72587 NumberInput, para formateo de numeros 2025-05-05 15:45:07 -04:00
ebe31a3d3d Guardar UF en DB 2025-05-05 15:40:55 -04:00
db6445bcf3 Cleanup View 2025-05-05 15:40:26 -04:00
4e1901b7c8 FatalErrors 2025-05-05 15:40:05 -04:00
c3316029c9 Se borra migracion duplicada 2025-05-05 14:01:39 -04:00
cbfc796685 Merge remote-tracking branch 'origin/feature/cierres' into feature/cierres 2025-05-05 11:35:29 -04:00
da56192f97 Formateo de numeros en JS 2025-04-30 23:36:32 -04:00
b5d08620f9 Unidades que no son departamentos 2025-04-30 17:13:40 -04:00
c92b07ee6f Excepcion correcta 2025-04-30 17:13:26 -04:00
ee6956d417 Reorden 2025-04-30 16:18:20 -04:00
21d5e2d03b Api en archivo separado 2025-04-30 16:18:00 -04:00
73a742c01e Nada en public 2025-04-30 10:51:47 -04:00
dd42c12d49 Orden 2025-04-30 10:38:20 -04:00
41ea5f5c15 Update prueba 2025-04-30 10:38:05 -04:00
eeb6f5bcd1 Se agrega condicion 2025-04-30 10:37:57 -04:00
2680f51167 Correccion migracion 2025-04-30 10:37:41 -04:00
019d57a0b0 Nuevas pruebas 2025-04-30 01:12:23 -04:00
1a400d9a5c Watcher solo para unit tests 2025-04-30 01:12:09 -04:00
6276f87274 Pruebas nuevas 2025-04-30 00:14:38 -04:00
28c93a42bc Logs de pruebas 2025-04-30 00:14:24 -04:00
4ff5d28522 Nuevas pruebas 2025-04-29 23:57:59 -04:00
a93642c55d Actualizacion de pruebas con extensiones 2025-04-29 23:57:49 -04:00
87c0d8c8d9 Se mueve todo a extension de pruebas 2025-04-29 23:55:51 -04:00
dd1741a930 Broker test 2025-04-29 23:21:19 -04:00
ad0fd82a9e Assert nuevo 2025-04-29 23:21:13 -04:00
bae5c1740d No mas require 2025-04-29 23:19:05 -04:00
f5f1482b7a Autoload para pruebas 2025-04-29 23:18:55 -04:00
4bd5fe16df Comandos para correr pruebas y consola 2025-04-29 23:18:18 -04:00
61845fbd05 Ignorar datos de pruebas 2025-04-29 22:26:26 -04:00
f8ac0f14f0 Abstracts 2025-04-29 22:25:32 -04:00
acb7a1336d Coverage lento e innecesario 2025-04-29 22:25:11 -04:00
8af56137a8 Seeds al migrar 2025-04-29 21:51:19 -04:00
c3247838b3 Namespace test Servicio Valor 2025-04-29 21:43:21 -04:00
dd82ac6bb7 Tests Home 2025-04-29 21:42:57 -04:00
2acf0362fa Ambiente de testeo 2025-04-29 21:41:49 -04:00
e6892ee085 Valor de PU cuando unidad no tiene valor 2025-04-29 13:01:57 -04:00
86b8d6b3c7 Limpieza 2025-04-29 13:01:21 -04:00
53115b085f Asegurarse que el valor entregado a Pago es en pesos. 2025-04-29 11:29:23 -04:00
c3b7427f60 Cambio en nombre de metodo y uso de valor maximo para UF 2025-04-29 11:20:49 -04:00
5d939f970b Valor con pruebas 2025-04-28 20:20:43 -04:00
4845801b27 Uso de script central de rut 2025-04-28 19:00:40 -04:00
d5bf9a7660 Digito verificador 2025-04-28 18:59:37 -04:00
795dda868b Ya no se incluye UF/m² y se transforman en numeros las UF 2025-04-25 20:03:11 -04:00
53a3633dc7 Menu -> Agregar Venta separado 2025-04-25 20:02:24 -04:00
0143fd11ac Se pasan datos a EmptyResult en base- 2025-04-25 19:41:42 -04:00
55745a8d0a EmptyResult ahora puede llevar los datos. 2025-04-25 19:41:23 -04:00
2a1930c5f7 FIX: Propiedad con unidad_principal 2025-04-25 19:25:16 -04:00
31f49dddb6 FIX: unidad_principal no tiene valor por defecto. 2025-04-25 17:36:12 -04:00
b4ca59fb6d Optimizacion de obtencion de datos. 2025-04-24 19:23:39 -04:00
d910f3eb69 FIX: Propiedad sin unidad_principal 2025-04-24 18:54:54 -04:00
555cdb7138 Promociones en misma tabla para tipo 2025-04-24 18:50:04 -04:00
65088da2f5 Promociones en misma tabla para tipo 2025-04-23 16:49:52 -04:00
966b341b65 Listado de promociones 2025-04-22 18:34:23 -04:00
90b05ca25c Se elimina la comision del excel 2025-04-22 16:28:13 -04:00
bb3a2fffa1 Cuando no existen promociones 2025-04-22 15:38:30 -04:00
8a5e41a722 Normalizacion con profundidad 2025-04-22 15:31:55 -04:00
5736a346e7 Valor debiese ser el último precio. 2025-04-22 15:24:11 -04:00
4f4e69f0c3 FIX: no tiene precio ahora, solo valor 2025-04-22 15:19:25 -04:00
00deebeaa8 FIX: faltaba valor 2025-04-22 15:19:08 -04:00
aee0754b5a Simplificacion de retorno de ventas por unidades 2025-04-22 15:18:59 -04:00
eabdab23c3 Simplificacion de retorno de ventas por unidades 2025-04-22 13:08:15 -04:00
5147450ed6 Manejo de excepciones 2025-04-22 13:07:52 -04:00
ed96f25475 Mayor orden 2025-04-22 11:49:34 -04:00
d5a3512852 Barras de progreso 2025-04-22 11:35:56 -04:00
d6730cd020 Cambio en link 2025-04-22 09:29:14 -04:00
c7dddc818c Definicion de variables una sola vez 2025-04-22 09:28:45 -04:00
33b4182bd3 Optimizacion de queries a cargar de una sola vez 2025-04-22 09:28:12 -04:00
fc776e6cec Ruta para Ventas por unidades 2025-04-21 19:43:20 -04:00
5d79ea83c3 Mostrar valor de venta para unidades vendidas 2025-04-21 19:43:01 -04:00
c34048a53a Ventas por unidades 2025-04-21 19:41:20 -04:00
f7af93b815 Throw Read 2025-04-21 19:40:26 -04:00
993e4ff3b8 Merge branch 'develop' into feature/cierres 2025-04-11 13:35:13 -04:00
bc49ba7629 FIX: Busqueda no funcionaba 2025-04-09 09:29:53 -04:00
3c2b486083 Se agregan columnas y el calculo de promociones de tipo fijo 2025-04-08 19:04:46 -04:00
76f69f3bda Optimizacion simple 2025-04-08 18:38:18 -04:00
8ba3c456b6 Link a contrato en vez del proyecto 2025-04-08 18:35:07 -04:00
98b18fab3e Cambios solicitados 2025-04-08 18:30:14 -04:00
12a4831887 Merge branch 'develop' into feature/cierres 2025-04-04 13:23:00 -03:00
da46914de4 Promociones en Contrato 2025-04-04 12:56:49 -03:00
596bc71cf8 Mejoras UI 2025-04-04 12:54:51 -03:00
7f8e4ea943 FIX: query fallaba 2025-04-04 12:36:03 -03:00
5456485f71 FIX: ya no existe relacion con contratos 2025-04-04 12:08:46 -03:00
836503a71b Menus nuevos 2025-04-04 12:08:24 -03:00
4df0cca675 Filtro en excel 2025-04-04 11:53:25 -03:00
00a0adb4ac Espacio mas ajustado 2025-04-04 11:53:11 -03:00
037fcd60f3 Orden de queries 2025-04-04 11:52:50 -03:00
7a97fc9dfe Precios con promociones para listado brokers 2025-04-03 17:22:38 -03:00
7b2df74e4d Promociones para cada subdivicion 2025-04-03 17:22:11 -03:00
b5d6d0acb9 Mostrar porcentajes en venta 2025-04-03 13:56:11 -03:00
8a1e6a7761 Conecciones de Promociones 2025-04-03 13:15:56 -03:00
ced673e452 Correcto nombre de tabla 2025-04-03 13:12:57 -03:00
8a7a1d4e64 Merge branch 'develop' into feature/cierres 2025-03-27 11:44:54 -03:00
9be20ab1cd UF 0 o nula actualizadas para Pago y Pie 2025-03-26 16:54:53 -03:00
1c40f18624 Pagos sin uf retornan 0 2025-03-26 16:49:27 -03:00
db36549699 Agregar Pie 2025-03-26 16:41:54 -03:00
4ce83fb270 Merge branch 'develop' into feature/cierres 2025-03-26 15:42:47 -03:00
b191a01313 Promociones 2025-03-25 19:22:38 -03:00
d3b0026ca4 Agregar, editar y eliminar promociones 2025-03-18 19:13:47 -03:00
2b3f476df7 Agregar, editar y eliminar promociones 2025-03-18 19:12:59 -03:00
39c148b7b3 Cambio nombre archivo 2025-03-17 23:03:06 -03:00
bae0f1f555 Separacion de Promocion de Contrato y Precio
"Simplificacion" de datos en listado de precios
2025-03-17 22:49:48 -03:00
2e49e2c947 Listados separados por hojas (tabs) 2025-03-13 13:16:20 -03:00
68aebdb4fe Listado de Precios para Contrato Broker 2025-03-13 12:18:08 -03:00
346001db8e SearchBuilder configuration centralizada
FIX: CentroCosto TipoCuenta
2025-03-13 09:33:42 -03:00
8b04eb262f FIX: Editar datos Broker 2025-03-12 18:31:21 -03:00
7c7c8315e2 Editar Brokers y sus contratos 2025-03-11 17:41:11 -03:00
510e05e5ca FIX: rut con otros caracteres y maximo largo 2025-03-07 17:26:36 -03:00
5055d2703c Broker Contact 2025-03-07 17:11:59 -03:00
2bc30ab9e8 Formatear porcentajes menores a 1 2025-03-07 17:11:15 -03:00
c7ee440e03 Listado de brokers 2025-03-06 20:34:43 -03:00
18dd8c4ec0 Merge branch 'develop' into feature/cierres 2025-03-06 16:23:58 -03:00
8ea4995f6b Contratos desde proyectos 2025-03-03 21:46:53 -03:00
aeeca65d94 Correcciones 2025-03-03 21:41:43 -03:00
5f69069aa0 Rutas Reservations 2025-03-03 16:53:36 -03:00
095a65a643 Cleanup por recomendaciones 2025-03-03 16:37:40 -03:00
928d2e57be Merge branch 'develop' into feature/cierres 2025-03-03 15:32:25 -03:00
2a0335f834 Reservation Controller 2025-03-03 15:21:18 -03:00
9ccf53fa4e Reservation Service 2025-03-03 15:21:12 -03:00
ef54c36edc Cleanup 2025-03-03 14:56:18 -03:00
4aa88d5164 Rutas API Contratos 2025-03-03 11:26:45 -03:00
8ea13c3efd API Contratos 2025-03-03 10:47:48 -03:00
12e3d7ed3b Servicio Contratos 2025-03-01 13:26:55 -03:00
a7fc89ac29 Merge branch 'develop' into feature/cierres 2025-02-24 21:36:35 -03:00
a71df4e70d Controlador y ruta de operadores para API 2025-02-24 12:41:50 -03:00
f17b7a758a withJson con error 2025-02-24 12:41:34 -03:00
7fb28cd44c Servicio operadores 2025-02-24 12:41:13 -03:00
a44bd610ad Excepciones de servicios 2025-02-24 12:41:00 -03:00
28bba8a438 Actualizacion de Modelos 2025-02-24 12:40:40 -03:00
0ec6ebdafe Actualizacion de Repos 2025-02-24 12:39:42 -03:00
3ebe256a66 Actualizacion de migraciones 2025-02-24 12:39:25 -03:00
9d135e2c26 Base de Datos 2025-02-18 16:02:10 -03:00
79 changed files with 469 additions and 2597 deletions

View File

@ -3,8 +3,7 @@ FROM php:8.4-cli
ENV TZ "${TZ}"
ENV APP_NAME "${APP_NAME}"
RUN apt-get update && apt-get install -y --no-install-recommends cron rsyslog nano beanstalkd \
&& rm -r /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends cron rsyslog nano && rm -r /var/lib/apt/lists/*
RUN pecl install xdebug-3.4.2 \
&& docker-php-ext-enable xdebug \

View File

@ -3,7 +3,7 @@ FROM php:8.4-fpm
ENV TZ=America/Santiago
RUN apt-get update && apt-get install -y --no-install-recommends libzip-dev libicu-dev git \
libpng-dev unzip tzdata libxml2-dev beanstalkd \
libpng-dev unzip tzdata libxml2-dev \
&& rm -r /var/lib/apt/lists/* \
&& docker-php-ext-install pdo pdo_mysql zip intl gd bcmath dom \
&& pecl install xdebug-3.4.2 \

0
app/bin/console Executable file → Normal file
View File

0
app/bin/integration_tests Executable file → Normal file
View File

0
app/bin/performance_tests Executable file → Normal file
View File

0
app/bin/unit_tests Executable file → Normal file
View File

View File

@ -8,13 +8,11 @@
"ext-gd": "*",
"ext-openssl": "*",
"ext-pdo": "*",
"ext-sockets": "*",
"berrnd/slim-blade-view": "^1",
"guzzlehttp/guzzle": "^7",
"monolog/monolog": "^3",
"nyholm/psr7": "^1",
"nyholm/psr7-server": "^1",
"pda/pheanstalk": "^7.0",
"php-di/php-di": "^7",
"php-di/slim-bridge": "^3",
"phpoffice/phpspreadsheet": "^3",

View File

@ -125,7 +125,7 @@ pm = ondemand
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 2
pm.max_children = 5
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'

View File

@ -19,18 +19,14 @@ final class CreateTokuAccounts extends AbstractMigration
*/
public function change(): void
{
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
$this->table('toku_accounts')
->addColumn('sociedad_rut', 'integer', ['limit' => 8, 'signed' => false, 'null' => false])
->addColumn('toku_id', 'string', ['length' => 255, 'null' => false])
->addColumn('account_key', 'string', ['length' => 255, 'null' => false])
->addColumn('enabled', 'boolean', ['default' => true])
->addTimestamps()
#->addForeignKey('sociedad_rut', 'inmobiliaria', 'rut', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
->addIndex(['toku_id'], ['unique' => true])
->addForeignKey('sociedad_rut', 'inmobiliaria', 'rut', ['delete' => 'CASCADE', 'update' => 'CASCADE'])
->addTimestamps()
->create();
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
}
}

View File

@ -1,26 +0,0 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class ChangeTelefonoSizeInPropietario extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$this->table('propietario')
->changeColumn('telefono', 'biginteger', ['null' => true, 'signed' => false, 'default' => null])
->update();
}
}

View File

@ -2,9 +2,9 @@
use Incoviba\Controller\API\Queues;
$app->group('/queue', function($app) {
#$app->get('/jobs[/]', [Queues::class, 'jobs']);
$app->get('/jobs[/]', [Queues::class, 'jobs']);
$app->group('/run', function($app) {
#$app->get('/{job_id:[0-9]+}[/]', [Queues::class, 'run']);
$app->get('/{job_id:[0-9]+}[/]', [Queues::class, 'run']);
$app->get('[/]', Queues::class);
});
});

View File

@ -2,7 +2,6 @@
use Incoviba\Controller\API\Ventas\Precios;
$app->group('/precios', function($app) {
$app->post('/import[/]', [Precios::class, 'import']);
$app->post('[/]', [Precios::class, 'proyecto']);
});
$app->group('/precio', function($app) {

View File

@ -2,5 +2,5 @@
use Incoviba\Controller\Ventas\Precios;
$app->group('/precios', function($app) {
$app->get('[/{project_id}[/]]', Precios::class);
$app->get('[/]', Precios::class);
});

View File

@ -156,7 +156,7 @@
<script>
const regiones = [
@foreach ($regiones as $region)
'<div class="item" data-value="{{$region->id}}">{{$region->numeral}} - {{$region->descripcion}}</div>',
'<div class="item" data-value="{{$region->id}}">{{$region->descripcion}}</div>',
@endforeach
]

View File

@ -54,23 +54,22 @@
}
$(document).ready(() => {
const url = '{{$urls->api}}/ventas/pago/{{$venta->resciliacion()->id}}'
let old = new Date(Date.parse('{{$venta->resciliacion()?->fecha->format('Y-m-d') ?? $venta->currentEstado()->fecha->format('Y-m-d') ?? $venta->fecha->format('Y-m-d')}}') + 24 * 60 * 60 * 1000)
let old = new Date({{$venta->resciliacion()?->fecha->format('Y') ?? date('Y')}},
{{$venta->resciliacion()?->fecha->format('n') ?? date('n')}}-1, {{$venta->resciliacion()?->fecha->format('j') ?? date('j')}})
calendar_date_options['initialDate'] = old
calendar_date_options['onChange'] = function(date, text, mode) {
if (date.getTime() === old.getTime()) {
return
}
const body = new FormData()
const fecha = new Date(date.getTime())
fecha.setDate(fecha.getDate() - 1)
body.set('fecha', fecha.toISOString())
body.set('fecha', date.toISOString())
$('#loading-spinner-fecha').show()
APIClient.fetch(url, {method: 'post', body}).then(response => {
$('#loading-spinner-fecha').hide()
if (!response) {
return
}
old = new Date(date.getTime())
old = date
alertResponse('Fecha cambiada correctamente.')
})
}

View File

@ -6,26 +6,15 @@
@section('venta_content')
<div class="ui list">
@if (isset($venta->formaPago()->pie))
<div class="item">
<div class="header">Valor Pagado</div>
<div class="content">
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
<div class="ui left pointing small label">
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
<div class="item">
<div class="header">Valor Pagado</div>
<div class="content">
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
<div class="ui left pointing small label">
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
</div>
@else
<div class="item">
<div class="ui compact warning message">
<div class="content">
<i class="exclamation triangle icon"></i>
No tiene valor pagado
</div>
</div>
</div>
@endif
</div>
<div class="item">
<div class="header">
Multa Estandar

View File

@ -24,9 +24,6 @@
<button class="ui tiny green icon button" id="add_button">
<i class="plus icon"></i>
</button>
<button class="ui tiny green icon button" id="import_button">
<i class="upload icon"></i>
</button>
</div>
</div>
</h4>
@ -34,7 +31,6 @@
<table class="ui table" id="list_data"></table>
</div>
</div>
@include('ventas.precios.modal.import')
<div class="ui modal" id="list_modal">
<div class="header">
Actualizar <span id="modal_title"></span>
@ -101,8 +97,7 @@
return this.precio / this.superficie
}
draw(formatter) {
const dateParts = this.fecha.split('-')
const date = new Date(dateParts[0], dateParts[1] - 1, dateParts[2])
const date = new Date(this.fecha)
const dateFormatter = new Intl.DateTimeFormat('es-CL')
return $('<tr></tr>').addClass('unidad').attr('data-linea', this.linea).append(
$('<td></td>').html(this.nombre)
@ -322,8 +317,7 @@
buttons: {
add: '',
up: '',
refresh: '',
import: ''
refresh: ''
}
},
data: {
@ -336,11 +330,6 @@
loading: {
precios: false
},
components: {
modals: {
import: null
}
},
get: function() {
return {
proyectos: () => {
@ -389,24 +378,6 @@
}
}
},
url() {
return {
proyectos: () => {
const currentUrl = window.location.href
const newUrl = `{{ $urls->base }}/ventas/precios`
if (newUrl !== currentUrl) {
window.history.replaceState(null, null, newUrl)
}
},
precios: proyecto_id => {
const currentUrl = window.location.href
const newUrl = `{{ $urls->base }}/ventas/precios/${proyecto_id}`
if (newUrl !== currentUrl) {
window.history.replaceState(null, null, newUrl)
}
}
}
},
add: function() {
return {
precio: data => {
@ -429,7 +400,6 @@
draw: function() {
return {
proyectos: () => {
this.url().proyectos()
const parent = $(this.ids.list)
const header = parent.find('#list_title')
const list = parent.find('.list')
@ -438,7 +408,6 @@
$(this.ids.buttons.add).hide()
$(this.ids.buttons.add).attr('data-id', '')
$(this.ids.buttons.add).attr('data-proyecto', '')
$(`#${this.ids.buttons.import}`).hide()
header.html('Proyectos')
table.hide()
@ -446,8 +415,7 @@
this.data.proyectos.forEach(proyecto => {
list.append(
$('<div></div>').addClass('item proyecto').attr('data-proyecto', proyecto.id)
.html(proyecto.descripcion).css('cursor', 'pointer')
$('<div></div>').addClass('item proyecto').attr('data-proyecto', proyecto.id).html(proyecto.descripcion).css('cursor', 'pointer')
)
})
list.show()
@ -463,7 +431,6 @@
})
},
precios: () => {
this.url().precios(this.data.id)
const parent = $(this.ids.list)
const header = parent.find('#list_title')
const list = parent.find('.list')
@ -473,8 +440,6 @@
$(this.ids.buttons.add).attr('data-proyecto', this.data.proyecto)
$(this.ids.buttons.add).show()
$(`#${this.ids.buttons.import}`).show()
header.html('Precios de ' + this.data.proyecto)
list.hide()
table.html('')
@ -616,27 +581,18 @@
}
}
},
import: event => {
event.preventDefault()
precios.components.modals.import.show(this.data.id)
return false
}
}
},
setup: function({list, proyectos, buttons_up, buttons_refresh, buttons_add, buttons_import}) {
setup: function({list, proyectos, buttons_up, buttons_refresh, buttons_add}) {
this.ids.list = list
this.ids.proyectos = proyectos
this.ids.buttons.up = buttons_up
this.ids.buttons.refresh = buttons_refresh
this.ids.buttons.add = buttons_add
this.ids.buttons.import = buttons_import
$(this.ids.buttons.up).click(this.actions().up)
$(this.ids.buttons.refresh).click(this.actions().refresh)
$(this.ids.buttons.add).click(this.actions().add().list)
document.getElementById(this.ids.buttons.import).addEventListener('click', this.actions().import)
this.components.modals.import = new ImportModal()
this.draw().proyectos()
}
@ -718,10 +674,6 @@
$(this.ids.button).click(this.actions().send)
}
}
function selectProject(projectId) {
const $project = $(`.item.proyecto[data-proyecto="${projectId}"]`)
$project.click()
}
$(document).ready(() => {
precios.setup({
@ -729,8 +681,7 @@
proyectos: '#proyectos',
buttons_up: '#up_button',
buttons_refresh: '#refresh_button',
buttons_add: '#add_button',
buttons_import: 'import_button'
buttons_add: '#add_button'
})
list_modal.setup({
modal: '#list_modal',
@ -741,10 +692,6 @@
fields_valor: '#valor',
button: '#send'
})
@if (isset($project_id))
selectProject({{$project_id}})
@endif
})
</script>
@endpush

View File

@ -1,120 +0,0 @@
<div class="ui modal" id="import_modal">
<div class="header">
Importar Precios
</div>
<div class="content">
<div class="ui form">
<input type="hidden" id="import_project_id" name="import_project_id" value="" />
<div class="three wide field">
<div class="ui calendar" id="import_date">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha" />
</div>
</div>
</div>
<input class="ui invisible file input" type="file" id="import_file" name="file" />
<label class="ui placeholder segment" for="import_file">
<div class="ui icon header">
<i class="upload icon"></i>
Archivo de Precios
</div>
</label>
</div>
</div>
<div class="actions">
<div class="ui red cancel icon button">
<i class="remove icon"></i>
</div>
<div class="ui green ok icon button">
<i class="checkmark icon"></i>
Importar
</div>
</div>
@push('page_scripts')
<script>
class ImportModal {
ids = {
modal: '',
project: '',
calendar: '',
file: ''
}
components = {
$modal: null,
form: null,
project: null,
$calendar: null,
file: null,
$file: null
}
constructor() {
this.ids.modal = 'import_modal'
this.ids.project = 'import_project_id'
this.ids.calendar = 'import_date'
this.ids.file = 'import_file'
this.setup()
}
show(project_id) {
this.components.project.value = project_id
this.components.$modal.modal('show')
}
dragDrop(event) {
event.preventDefault()
if (event.originalEvent.dataTransfer && event.originalEvent.dataTransfer.files.length > 0) {
this.components.file.files = event.originalEvent.dataTransfer.files
}
}
import() {
const url = '{{ $urls->api }}/ventas/precios/import'
const method = 'post'
const body = new FormData()
body.set('project_id', this.components.project.value)
const date = this.components.$calendar.calendar('get date')
body.set('date', [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'))
body.set('file', this.components.file.files[0])
APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
if (json.status === true) {
window.location.reload()
return
}
console.debug(json)
})
}
setup() {
this.components.$modal = $(`#${this.ids.modal}`)
this.components.$modal.modal({
onApprove: () => {
this.import()
}
})
this.components.form = this.components.$modal.find('form')
this.components.form.submit(event => {
event.preventDefault()
this.import()
return false
})
this.components.project = document.getElementById(this.ids.project)
this.components.$calendar = $(`#${this.ids.calendar}`)
const cdo = structuredClone(calendar_date_options)
cdo['maxDate'] = new Date()
this.components.$calendar.calendar(cdo)
this.components.file = document.getElementById(this.ids.file)
this.components.$file = $(this.components.file.parentNode.querySelector('label'))
this.components.$file.css('cursor', 'pointer')
this.components.$file.on('dragover', event => {
event.preventDefault()
event.stopPropagation()
})
this.components.$file.on('dragenter', event => {
event.preventDefault()
event.stopPropagation()
})
this.components.$file.on('drop', this.dragDrop.bind(this))
}
}
</script>
@endpush

View File

@ -116,18 +116,7 @@ return [
->registerSub($container->get(Incoviba\Service\Contabilidad\Cartola\BCI\Mes::class));
},
'TokuClient' => function(ContainerInterface $container) {
$logger = $container->get('externalLogger');
$stack = GuzzleHttp\HandlerStack::create();
$stack->push(GuzzleHttp\Middleware::mapRequest(function(Psr\Http\Message\RequestInterface $request) use ($logger) {
$logger->info('Toku Request', [
'method' => $request->getMethod(),
'uri' => (string) $request->getUri(),
'headers' => $request->getHeaders(),
'body' => $request->getBody()->getContents(),
]);
}));
return new GuzzleHttp\Client([
'handler' => $stack,
'base_uri' => $container->get('TOKU_URL'),
'headers' => [
'x-api-key' => $container->get('TOKU_TOKEN'),
@ -173,16 +162,6 @@ return [
->register('subscription', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Subscription::class))
->register('invoice', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Invoice::class));
},
Pheanstalk\Pheanstalk::class => function(ContainerInterface $container) {
return Pheanstalk\Pheanstalk::create(
$container->get('BEANSTALKD_HOST'),
$container->has('BEANSTALKD_PORT') ? $container->get('BEANSTALKD_PORT') : 11300
);
},
Incoviba\Service\MQTT::class => function(ContainerInterface $container) {
return new Incoviba\Service\MQTT()
->register('default', $container->get(Incoviba\Service\MQTT\Pheanstalk::class));
},
Incoviba\Service\Queue::class => function(ContainerInterface $container) {
return new Incoviba\Service\Queue(
$container->get(Psr\Log\LoggerInterface::class),
@ -224,9 +203,5 @@ return [
$container->get(Incoviba\Service\Queue::class)
)
->register($container->get(Incoviba\Service\Venta\MediosPago\Toku::class));
},
Incoviba\Service\FileUpload::class => function(ContainerInterface $container) {
return new Incoviba\Service\FileUpload($container->get(Psr\Log\LoggerInterface::class))
->register($container->get(Incoviba\Service\FileUpload\ExcelBase::class));
}
];

View File

@ -22,4 +22,20 @@ class Queues extends Ideal\Controller
}
return $this->withJson($response, $output);
}
public function jobs(ServerRequestInterface $request, ResponseInterface $response,
Service\Queue $queueService): ResponseInterface
{
$output = [
'jobs' => array_column($queueService->getPendingJobs(), 'id')
];
return $this->withJson($response, $output);
}
public function run(ServerRequestInterface $request, ResponseInterface $response, Service\Queue $queueService,
int $job_id): ResponseInterface
{
if ($queueService->runJob($job_id, $request)) {
return $response->withStatus(200);
}
return $response->withStatus(422);
}
}

View File

@ -1,16 +1,13 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use DateTime;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult};
use Psr\Log\LoggerInterface;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\{withJson,emptyBody};
use Incoviba\Controller\withRedis;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Service;
use Incoviba\Controller\withRedis;
class Precios
{
@ -54,29 +51,4 @@ class Precios
}
}
}
public function import(ServerRequestInterface $request, ResponseInterface $response,
LoggerInterface $logger,
Service\Venta\Precio $precioService): ResponseInterface
{
$body = $request->getParsedBody();
$projectId = $body['project_id'];
$date = $body['date'];
$file = $request->getUploadedFiles()['file'];
$output = [
'input' => $body,
'total' => 0,
'precios' => [],
'status' => false
];
$date = DateTime::createFromFormat('Y-m-d', $date);
try {
$output['precios'] = $precioService->import($projectId, $date, $file);
$output['total'] = count($output['precios']);
$output['status'] = true;
} catch (Create | Exception $exception) {
$logger->warning($exception);
}
return $this->withJson($response, $output);
}
}

View File

@ -4,9 +4,6 @@ namespace Incoviba\Controller;
use Incoviba\Common\Alias\View;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
@ -145,24 +142,9 @@ class Ventas
return $view->render($response, 'ventas.desistir', compact('venta'));
}
public function desistida(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
Service\Venta\Pago $pagoService,
View $view, int $venta_id): ResponseInterface
{
try {
$venta = $ventaService->getById($venta_id);
} catch (Read) {
return $view->render($response->withStatus(404), 'not_found');
}
if ($venta->resciliacion() === null) {
$pagoData = [
'fecha' => $venta->currentEstado()->fecha->format('Y-m-d'),
'valor' => 0
];
try {
$pago = $pagoService->add($pagoData);
$venta = $ventaService->edit($venta, ['resciliacion' => $pago->id]);
} catch (Create | Update) {}
}
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.desistida', compact('venta'));
}
}

View File

@ -9,9 +9,9 @@ use Incoviba\Model;
class Precios
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService, ?int $project_id = null): ResponseInterface
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Proyecto $proyectoService): ResponseInterface
{
$proyectos = array_map(function(Model\Proyecto $proyecto) {return ['id' => $proyecto->id, 'descripcion' => $proyecto->descripcion];}, $proyectoService->getVendibles());
return $view->render($response, 'ventas.precios.list', compact('proyectos', 'project_id'));
return $view->render($response, 'ventas.precios.list', compact('proyectos'));
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Incoviba\Exception;
use Throwable;
use Exception;
abstract class MQTT extends Exception
{
public function __construct($message = "", $code = 0, ?Throwable $previous = null)
{
$baseCode = 700;
$code = $baseCode + $code;
if ($message == "") {
$message = "MQTT Exception";
}
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class MissingClient extends MQTT
{
public function __construct(string $host = '', ?Throwable $previous = null)
{
$message = 'Missing MQTT client';
if ($host !== '') {
$message = "{$message} for host {$host}";
}
$code = 1;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class MissingJob extends MQTT
{
public function __construct(?Throwable $previous = null)
{
$message = 'Missing MQTT job';
$code = 10;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class RemoveJob extends MQTT
{
public function __construct(int $jobId, ?Throwable $previous = null)
{
$message = "Could not remove job {$jobId}";
$code = 13;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class SetJob extends MQTT
{
public function __construct(string $payload, ?Throwable $previous = null)
{
$message = "Could not set job with {$payload}";
$code = 11;
parent::__construct($message, $code, $previous);
}
}

View File

@ -43,11 +43,6 @@ class Inmobiliaria extends Ideal\Repository
return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data);
}
/**
* @param string|array|null $sorting
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchAllActive(null|string|array $sorting = null): array
{
$query = $this->connection->getQueryBuilder()
@ -63,18 +58,4 @@ class Inmobiliaria extends Ideal\Repository
}
return $this->fetchMany($query, [1, 8]);
}
/**
* @param string $name
* @return Model\Inmobiliaria
* @throws Implement\Exception\EmptyResult
*/
public function fetchByName(string $name): Model\Inmobiliaria
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('razon LIKE :name OR abreviacion LIKE :name');
return $this->fetchOne($query, ['name' => "%{$name}%"]);
}
}

View File

@ -85,11 +85,6 @@ class Proyecto extends Ideal\Repository
return $this->fetchOne($query, [$id]);
}
/**
* @param string $name
* @return Model\Proyecto
* @throws Implement\Exception\EmptyResult
*/
public function fetchByName(string $name): Model\Proyecto
{
$query = $this->connection->getQueryBuilder()

View File

@ -7,8 +7,6 @@ use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
use PDO;
use PDOException;
class EstadoPrecio extends Ideal\Repository
{
@ -46,24 +44,11 @@ class EstadoPrecio extends Ideal\Repository
return $this->update($model, ['precio', 'estado', 'fecha'], $new_data);
}
/**
* @param int $precio_id
* @return array
* @throws Implement\Exception\EmptyResult
*/
public function fetchByPrecio(int $precio_id): array
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `precio` = ?";
error_log($query.PHP_EOL,3,'/logs/query.log');
error_log($precio_id.PHP_EOL,3,'/logs/query.log');
return $this->fetchMany($query, [$precio_id]);
}
/**
* @param int $precio_id
* @return Define\Model
* @throws Implement\Exception\EmptyResult
*/
public function fetchCurrentByPrecio(int $precio_id): Define\Model
{
$query = "SELECT e1.*

View File

@ -1,7 +1,6 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Implement\Exception\EmptyResult;
use PDO;
use PDOException;
use Incoviba\Common\Ideal;

View File

@ -4,7 +4,6 @@ namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
class TipoEstadoPrecio extends Ideal\Repository
@ -32,18 +31,4 @@ class TipoEstadoPrecio extends Ideal\Repository
{
return $this->update($model, ['descripcion'], $new_data);
}
/**
* @param string $descripcion
* @return Model\Venta\TipoEstadoPrecio
* @throws EmptyResult
*/
public function fetchByDescripcion(string $descripcion): Model\Venta\TipoEstadoPrecio
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('descripcion = ?');
return $this->fetchOne($query, [$descripcion]);
}
}

View File

@ -1,59 +0,0 @@
<?php
namespace Incoviba\Service;
use InvalidArgumentException;
use Psr\Http\Message\UploadedFileInterface;
use Incoviba\Common\Ideal;
use Incoviba\Exception\ServiceAction;
use Incoviba\Service\FileUpload\FileUploadInterface;
class FileUpload extends Ideal\Service implements FileUploadInterface
{
protected array $uploads = [];
public function register(FileUploadInterface $fileUpload, string $filetype = 'default'): self
{
$this->uploads [$filetype]= $fileUpload;
return $this;
}
/**
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws ServiceAction\Read
*/
public function getData(UploadedFileInterface $uploadedFile): array
{
try {
$type = $this->getFileType($uploadedFile);
} catch (InvalidArgumentException $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
$uploader = $this->getUploader($type);
return $uploader->getData($uploadedFile);
}
/**
* @param UploadedFileInterface $uploadedFile
* @return string|null
*/
protected function getFileType(UploadedFileInterface $uploadedFile): ?string
{
$fileType = $uploadedFile->getClientMediaType();
$typesMap = [
'text/csv' => 'csv',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
'application/vnd.ms-excel' => 'xls',
];
if (!array_key_exists($fileType, $typesMap)) {
throw new InvalidArgumentException("File type {$fileType} not supported.");
}
return $typesMap[$fileType];
}
protected function getUploader(string $type): FileUploadInterface
{
if (!array_key_exists($type, $this->uploads)) {
return $this->uploads['default'];
}
return $this->uploads[$type];
}
}

View File

@ -1,147 +0,0 @@
<?php
namespace Incoviba\Service\FileUpload;
use InvalidArgumentException;
use OutOfBoundsException;
use Psr\Http\Message\UploadedFileInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Ideal;
use Incoviba\Exception\ServiceAction\Read;
class ExcelBase extends Ideal\Service implements FileUploadInterface
{
/**
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws Read
*/
public function getData(UploadedFileInterface $uploadedFile): array
{
$tempFilename = $this->createTempFile($uploadedFile);
$reader = PhpSpreadsheet\IOFactory::createReaderForFile($tempFilename);
$reader->setReadDataOnly(true);
$workbook = $reader->load($tempFilename);
try {
$sheet = $this->findSheet($workbook);
} catch (OutOfBoundsException $exception) {
throw new Read(__CLASS__, $exception);
}
$titles = $this->extractTitles($sheet);
$data = $this->extractData($sheet, $titles);
unlink($tempFilename);
return $data;
}
/**
* @param PhpSpreadsheet\Spreadsheet $workbook
* @return PhpSpreadsheet\Worksheet\Worksheet
* @throws OutOfBoundsException
*/
protected function findSheet(PhpSpreadsheet\Spreadsheet $workbook): PhpSpreadsheet\Worksheet\Worksheet
{
$sheet = $workbook->getActiveSheet();
if ($this->findTable($sheet)) {
return $sheet;
}
$sheets = $workbook->getAllSheets();
foreach ($sheets as $sheet) {
if ($this->findTable($sheet)) {
return $sheet;
}
}
throw new OutOfBoundsException('No table found in the workbook.');
}
protected function findTable(PhpSpreadsheet\Worksheet\Worksheet $sheet): bool
{
$rowIterator = $sheet->getRowIterator();
foreach ($rowIterator as $row) {
if ($row->isEmpty()) {
continue;
}
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
if ($cellIterator->valid()) {
return true;
}
foreach ($cellIterator as $cell) {
if ($cell->getCalculatedValue() !== '') {
return true;
}
}
}
return false;
}
protected function createTempFile(UploadedFileInterface $uploadedFile): string
{
$filename = $uploadedFile->getClientFilename();
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$tempFilename = tempnam(sys_get_temp_dir(), $extension);
$uploadedFile->moveTo($tempFilename);
return $tempFilename;
}
protected function extractTitles(PhpSpreadsheet\Worksheet\Worksheet $sheet): array
{
$titles = [];
$iterator = $sheet->getRowIterator();
foreach ($iterator as $row) {
if ($row->isEmpty()) {
continue;
}
$titles = $this->getRowData($row);
break;
}
return $titles;
}
protected function extractData(PhpSpreadsheet\Worksheet\Worksheet $sheet, array $titles): array
{
$data = [];
$rowIterator = $sheet->getRowIterator();
foreach ($rowIterator as $row) {
if ($row->isEmpty()) {
continue;
}
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
if ($cellIterator->current() === $titles[0]) {
continue;
}
try {
$rowData = $this->getRowData($row, $titles);
} catch (InvalidArgumentException $exception) {
if ($exception->getCode() === 1000) {
continue;
}
throw $exception;
}
$data []= array_combine($titles, $rowData);
}
return $data;
}
protected function getRowData(PhpSpreadsheet\Worksheet\Row $row, ?array $titles = null): array
{
$data = [];
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell) {
if ($cell->getCalculatedValue() === null) {
continue;
}
$value = $cell->getCalculatedValue();
if ($value === null) {
continue;
}
$value = mb_strtolower($value);
if ($titles !== null and in_array($value, $titles)) {
throw new InvalidArgumentException('Row matches title', 1000);
}
$data []= $value;
}
return $data;
}
}

View File

@ -1,9 +0,0 @@
<?php
namespace Incoviba\Service\FileUpload;
use Psr\Http\Message\UploadedFileInterface;
interface FileUploadInterface
{
public function getData(UploadedFileInterface $uploadedFile): array;
}

View File

@ -5,43 +5,60 @@ use DateInvalidTimeZoneException;
use DateMalformedStringException;
use DateTimeImmutable;
use DateTimeZone;
use InvalidArgumentException;
use OutOfRangeException;
use Psr\Log\LoggerInterface;
use Predis\Connection\ConnectionException;
use Incoviba\Common\Ideal;
use Incoviba\Exception\MQTT as MQTTException;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\{Create, Delete, Read, Update};
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Model;
class Job extends Ideal\Service
{
public function __construct(LoggerInterface $logger, protected MQTT $mqttService,
public function __construct(LoggerInterface $logger, protected Redis $redisService,
protected Repository\Job $jobRepository)
{
parent::__construct($logger);
}
protected string $redisKey = 'jobs';
public function isPending(): bool
public function getPending(null|string|array $orderBy = null): array
{
try {
return $this->mqttService->exists();
} catch (MQTTException $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
return false;
$jobs = $this->redisService->get($this->redisKey);
if ($jobs === null) {
return [];
}
$jobs = json_decode($jobs, true);
if ($orderBy !== null) {
uksort($jobs, function($a, $b) use ($orderBy) {
return $a[$orderBy] <=> $b[$orderBy];
});
}
return array_map([$this, 'load'], $jobs);
} catch (ConnectionException | EmptyRedis) {
return [];
}
}
/**
* @param int $id
* @return Model\Job
* @throws Read
*/
public function get(): Model\Job
public function getPendingById(int $id): Model\Job
{
$jobs = $this->getJobs();
try {
return $this->load(json_decode($this->mqttService->get(), true));
} catch (MQTTException $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
$idx = $this->findJob($jobs, $id);
} catch (EmptyResult $exception) {
$exception = new OutOfRangeException('Job not found', count($jobs), $exception);
throw new Read(__CLASS__, $exception);
}
return $this->load($jobs[$idx]);
}
/**
@ -54,7 +71,6 @@ class Job extends Ideal\Service
try {
$now = (new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')));
} catch (DateMalformedStringException | DateInvalidTimeZoneException $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception]);
$now = new DateTimeImmutable();
}
$data = [
@ -65,9 +81,17 @@ class Job extends Ideal\Service
'updated_at' => null,
'retries' => 0
];
$jobs = [];
try {
$this->mqttService->set(json_encode($data));
} catch (MQTTException $exception) {
$jobs = $this->redisService->get($this->redisKey);
if ($jobs !== null) {
$jobs = json_decode($jobs, true);
}
} catch (EmptyRedis) {}
$jobs []= $data;
try {
$this->redisService->set($this->redisKey, json_encode($jobs), -1);
} catch (ConnectionException $exception) {
throw new Create(__CLASS__, $exception);
}
return $this->load($data);
@ -75,35 +99,50 @@ class Job extends Ideal\Service
/**
* @param Model\Job $job
* @return void
* @return Model\Job
* @throws Update
* @throws Read
*/
public function update(Model\Job $job): void
public function update(Model\Job $job): Model\Job
{
try {
$now = (new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')));
} catch (DateMalformedStringException | DateInvalidTimeZoneException) {
$now = new DateTimeImmutable();
}
$data = json_decode(json_encode($job), true);
$data['updated_at'] = $now->format('Y-m-d H:i:s');
$jobs = $this->getJobs();
try {
$this->mqttService->update(json_encode($data));
} catch (MQTTException $exception) {
$idx = $this->findJob($jobs, $job->id);
} catch (EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}
$jobs[$idx]['updated_at'] = $now->format('Y-m-d H:i:s');
$jobs[$idx]['retries'] = $job->retries;
try {
$this->redisService->set($this->redisKey, json_encode($jobs), -1);
} catch (ConnectionException $exception) {
throw new Update(__CLASS__, $exception);
}
return $this->load($jobs[$idx]);
}
/**
* @param Model\Job $job
* @throws Read
* @throws Delete
*/
public function remove(Model\Job $job): void
{
$jobs = $this->getJobs();
try {
$this->mqttService->remove();
} catch (MQTTException $exception) {
$idx = $this->findJob($jobs, $job->id);
} catch (EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}
unset($jobs[$idx]);
try {
$this->redisService->set($this->redisKey, json_encode(array_values($jobs)), -1);
} catch (ConnectionException $exception) {
throw new Delete(__CLASS__, $exception);
}
}
@ -111,18 +150,59 @@ class Job extends Ideal\Service
/**
* @param Model\Job $job
* @return bool
* @throws Read | Create
*/
public function execute(Model\Job $job): bool
{
$jobs = $this->getJobs();
try {
$this->mqttService->remove();
return true;
} catch (MQTTException $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
return false;
$idx = $this->findJob($jobs, $job->id);
} catch (EmptyResult $exception) {
$exception = new OutOfRangeException('Job not found', count($jobs), $exception);
throw new Read(__CLASS__, $exception);
}
unset($jobs[$idx]);
try {
$this->redisService->set($this->redisKey, json_encode(array_values($jobs)), -1);
} catch (ConnectionException $exception) {
throw new Create(__CLASS__, $exception);
}
return true;
}
/**
* @return array
* @throws Read
*/
protected function getJobs(): array
{
try {
$jobs = $this->redisService->get($this->redisKey);
} catch (EmptyRedis $exception) {
throw new Read(__CLASS__, $exception);
}
if ($jobs === null) {
$exception = new InvalidArgumentException("Redis Key {$this->redisKey} not found");
throw new Read(__CLASS__, $exception);
}
return json_decode($jobs, true);
}
/**
* @param array $jobs
* @param int $id
* @return int
* @throws EmptyResult
*/
protected function findJob(array $jobs, int $id): int
{
$idx = array_find_key($jobs, function($job) use ($id) {
return (int) $job['id'] === $id;
});
if ($idx === null) {
throw new EmptyResult("SELECT * FROM jobs WHERE id = ?");
}
return $idx;
}
protected function load(array $data, ?int $id = null): Model\Job
{
$job = new Model\Job();

View File

@ -1,102 +0,0 @@
<?php
namespace Incoviba\Service;
use Incoviba\Exception\MQTT as MQTTException;
use Incoviba\Service\MQTT\MQTTInterface;
class MQTT implements MQTTInterface
{
protected array $clients = [];
public function register(string $name, MQTTInterface $client): self
{
$this->clients[$name] = $client;
return $this;
}
public function clientExists(string $name): bool
{
return isset($this->clients[$name]);
}
/**
* @param string|null $name
* @return MQTTInterface
* @throws MQTTException/MissingClient
*/
public function getClient(?string $name = null): MQTTInterface
{
if ($name === null) {
$name = array_keys($this->clients)[0];
}
if (!$this->clientExists($name)) {
throw new MQTTException\MissingClient($name);
}
return $this->clients[$name];
}
/**
* @param string|null $host
* @return bool
* @throws MQTTException/MissingClient
* @throws MQTTException/MissingJob
*/
public function exists(?string $host = null): bool
{
$client = $this->getClient($host);
return $client->exists();
}
/**
* @param string|null $host
* @return string
* @throws MQTTException/MissingClient
* @throws MQTTException/MissingJob
*/
public function get(?string $host = null): string
{
$client = $this->getClient($host);
return $client->get();
}
/**
* @param string $value
* @param int $delay
* @param string|null $host
* @return $this
* @throws MQTTException/MissingClient
* @throws MQTTException/SetJob
*/
public function set(string $value, int $delay = 0, ?string $host = null): self
{
$client = $this->getClient($host);
$client->set($value, $delay);
return $this;
}
/**
* @param int|null $jobId
* @param string|null $host
* @return $this
* @throws MQTTException/MissingJob
* @throws MQTTException/RemoveJob
*/
public function remove(?int $jobId = null, ?string $host = null): self
{
$this->getClient($host)->remove($jobId);
return $this;
}
/**
* @param string $newPayload
* @param int|null $jobId
* @param string|null $host
* @return $this
* @throws MQTTException/MissingJob
* @throws MQTTException/RemoveJob
* @throws MQTTException/SetJob
*/
public function update(string $newPayload, ?int $jobId = null, ?string $host = null): self
{
$this->getClient($host)->update($newPayload, $jobId);
return $this;
}
}

View File

@ -1,111 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Exception;
use Incoviba\Exception\MQTT\MissingJob;
use Incoviba\Exception\MQTT\RemoveJob;
use Incoviba\Exception\MQTT\SetJob;
use Psr\Log\LoggerInterface;
use xobotyi\beansclient;
use xobotyi\beansclient\Exception\ClientException;
use xobotyi\beansclient\Exception\CommandException;
use xobotyi\beansclient\Exception\JobException;
class Beanstalkd implements MQTTInterface
{
/**
* @throws JobException
* @throws ClientException
* @throws CommandException
*/
public function __construct(protected LoggerInterface $logger, protected beansclient\BeansClient $client,
protected string $tube = 'default', protected int $ttr = beansclient\BeansClient::DEFAULT_TTR,
protected int $priority = 1)
{
$this->client->watchTube($this->tube);
}
public function exists(): bool
{
try {
$stats = $this->client->statsTube($this->tube);
return $stats['current-jobs-ready'] > 0;
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
return false;
}
}
protected ?beansclient\Job $currentJob = null;
public function get(): string
{
if (!$this->exists()) {
throw new MissingJob();
}
try {
$job = $this->client->watchTube($this->tube)->reserve();
$this->currentJob = $job;
return $job->payload;
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
throw new MissingJob($exception);
}
}
/**
* @param string $value
* @param int $delay
* @return $this
* @throws SetJob
*/
public function set(string $value, int $delay = 0): self
{
try {
$this->client->useTube($this->tube)->put($value, $this->priority, $delay, $this->ttr ?? 0);
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['payload' => $value, 'delay' => $delay, 'exception' => $exception]);
throw new SetJob($value, $exception);
}
return $this;
}
/**
* @param string $newPayload
* @param int|null $jobId
* @return self
* @throws RemoveJob
* @throws SetJob
*/
public function update(string $newPayload, ?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJob->id;
}
return $this->remove($jobId)
->set($newPayload);
}
/**
* @param int|null $jobId
* @return $this
* @throws RemoveJob
*/
public function remove(?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJob->id;
}
try {
if (!$this->client->useTube($this->tube)->delete($jobId)) {
throw new JobException("Failed to delete job {$jobId}");
}
if ($this->currentJob !== null && $this->currentJob->id === $jobId) {
$this->currentJob = null;
}
} catch (Exception $exception) {
$this->logger->error($exception->getMessage(), ['jobId' => $jobId, 'exception' => $exception]);
throw new RemoveJob($jobId, $exception);
}
return $this;
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Incoviba\Exception\MQTT\MissingJob;
interface MQTTInterface {
/**
* @return bool
*/
public function exists(): bool;
/**
* @return string
* @throws MissingJob
*/
public function get(): string;
/**
* @param string $value
* @param int $delay
* @return self
*/
public function set(string $value, int $delay = 0): self;
public function remove(?int $jobId = null): self;
}

View File

@ -1,59 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Incoviba\Common\Ideal\Service;
use Psr\Log\LoggerInterface;
use Pheanstalk as PBA;
class Pheanstalk extends Service implements MQTTInterface
{
const string DEFAULT_TUBE = 'default';
const int DEFAULT_TTR = 60;
const int DEFAULT_PRIORITY = 1_024;
public function __construct(LoggerInterface $logger, protected PBA\Pheanstalk $client, string $tubeName = self::DEFAULT_TUBE)
{
parent::__construct($logger);
$this->tube = new PBA\Values\TubeName($tubeName);
}
protected PBA\Values\TubeName $tube;
public function set(string $value, int $delay = 0): self
{
$this->client->useTube($this->tube);
$this->client->put($value, self::DEFAULT_PRIORITY, $delay, self::DEFAULT_TTR);
return $this;
}
public function exists(): bool
{
$stats = $this->client->statsTube($this->tube);
return $stats->currentJobsReady > 0;
}
protected int $currentJobId;
public function get(): string
{
$this->client->useTube($this->tube);
$job = $this->client->reserve();
$this->currentJobId = $job->getId();
return $job->getData();
}
public function update(string $newPayload, ?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJobId;
}
$this->remove($jobId);
$this->set($newPayload);
return $this;
}
public function remove(?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJobId;
}
$this->client->useTube($this->tube);
$this->client->delete(new PBA\Values\JobId($jobId));
return $this;
}
}

View File

@ -7,7 +7,6 @@ use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Exception\ServiceAction\{Create, Delete, Read, Update};
use Incoviba\Service;
use Incoviba\Model;
class Queue extends Ideal\Service
{
@ -30,7 +29,7 @@ class Queue extends Ideal\Service
try {
$this->jobService->add($configuration);
return true;
} catch (Create $exception) {
} catch (Read $exception) {
$final = new Exception("Could not enqueue job", 0, $exception);
$this->logger->warning($final);
return false;
@ -41,8 +40,22 @@ class Queue extends Ideal\Service
return $this->enqueue($configuration);
}
public function runJob(Model\Job $job, ?RequestInterface $request = null): bool
/**
* @return array
*/
public function getPendingJobs(): array
{
return $this->jobService->getPending();
}
public function runJob(int $job_id, ?RequestInterface $request = null): bool
{
try {
$job = $this->jobService->getPendingById($job_id);
} catch (Read $exception) {
$this->logger->debug($exception);
return false;
}
$type = 'default';
if (isset($job->configuration['type'])) {
$type = strtolower($job->configuration['type']);
@ -58,57 +71,50 @@ class Queue extends Ideal\Service
try {
if (!$worker->execute($job)) {
$this->logger->debug("Could not execute job {$job->id}");
$job->retries++;
$this->jobService->update($job);
$this->logger->debug("Could not execute job {$job_id}");
return false;
}
if (!$this->jobService->execute($job)) {
$this->logger->debug("Could not remove job {$job->id}");
$this->logger->debug("Could not remove job {$job_id}");
return false;
}
} catch (Exception $exception) {
$this->logger->warning("Could not run job {$job->id}", ['exception' => $exception]);
$job->retries++;
try {
$this->jobService->update($job);
} catch (Update $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
}
$final = new Exception("Could not run job", 0, $exception);
$this->logger->warning($final);
return false;
}
return true;
}
public function run(?RequestInterface $request = null): bool
{
if (!$this->jobService->isPending()) {
$jobs = $this->jobService->getPending();
if (count($jobs) === 0) {
$this->logger->debug("No pending jobs");
return true;
}
try {
$job = $this->jobService->get();
} catch (Read $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
return false;
}
if ($job->retries >= $this->maxRetries) {
try {
$this->jobService->remove($job);
} catch (Delete $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
$errors = [];
foreach ($jobs as $job) {
if ($job->retries >= $this->maxRetries) {
try {
$this->jobService->remove($job);
} catch (Read | Delete $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
}
continue;
}
return true;
}
try {
$this->runJob($job, $request);
} catch (Exception) {
$job->retries ++;
try {
$this->jobService->update($job);
} catch (Update $exception) {
$this->logger->error($exception->getMessage(), ['job' => $job, 'exception' => $exception]);
$this->runJob($job->id, $request);
} catch (Exception) {
$job->retries ++;
try {
$this->jobService->update($job);
} catch (Read | Update $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
}
$errors []= $job->id;
}
return false;
}
return true;
return count($errors) === 0;
}
}

View File

@ -4,7 +4,7 @@ namespace Incoviba\Service;
use DateTimeInterface;
use DateTimeImmutable;
use DateMalformedStringException;
use Incoviba\Service\Valor\Phone;
use function PHPUnit\Framework\countOf;
class Valor
{
@ -40,14 +40,6 @@ class Valor
}
return $value / $this->ufService->get($date);
}
public function phone(): Phone
{
return new Phone();
}
public function telefono(): Phone
{
return $this->phone();
}
protected function getDateTime(null|string|DateTimeInterface $date): DateTimeInterface
{

View File

@ -1,28 +0,0 @@
<?php
namespace Incoviba\Service\Valor;
class Phone
{
public function toDatabase(?string $phone): ?int
{
if ($phone === null) {
return null;
}
return (int) str_replace([' ', '+'], '', $phone) ?? null;
}
public function toDisplay(?int $phone): ?string
{
if ($phone === null) {
return null;
}
$parts = preg_split('/(?=<country>\d{2})?(?=<area>\d)(?=<first>\d{4})(?=<last>\d{4})/', $phone);
$output = [];
if (array_key_exists('country', $parts)) {
$output [] = "+{$parts[0]}";
}
$output [] = $parts[1] ?? '';
$output [] = $parts[2] ?? '';
$output [] = $parts[3] ?? '';
return implode(' ', $output);
}
}

View File

@ -1,31 +1,19 @@
<?php
namespace Incoviba\Service\Venta;
use DateTimeInterface;
use PDOException;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction;
use Incoviba\Model;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
use Incoviba\Model;
class Precio extends Ideal\Service
class Precio
{
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Precio $precioRepository,
protected Repository\Venta\EstadoPrecio $estadoPrecioRepository,
protected Precio\Estado $estadoPrecioService,
protected Precio\Import $importService)
{
parent::__construct($logger);
}
public function __construct(protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\EstadoPrecio $estadoPrecioRepository) {}
/**
* @param int $proyecto_id
* @return array
* @throws ServiceAction\Read
* @throws Read
*/
public function getByProyecto(int $proyecto_id): array
{
@ -37,14 +25,14 @@ class Precio extends Ideal\Service
}
return $precios;
} catch (EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
throw new Read(__CLASS__, $exception);
}
}
/**
* @param int $unidad_id
* @return Model\Venta\Precio
* @throws ServiceAction\Read
* @throws Read
*/
public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio
{
@ -54,14 +42,14 @@ class Precio extends Ideal\Service
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
return $precio;
} catch (EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
throw new Read(__CLASS__, $exception);
}
}
/**
* @param int $unidad_id
* @return array
* @throws ServiceAction\Read
* @throws Read
*/
public function getByUnidad(int $unidad_id): array
{
@ -73,51 +61,7 @@ class Precio extends Ideal\Service
}
return $precios;
} catch (EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
throw new Read(__CLASS__, $exception);
}
}
/**
* @param int $projectId
* @param DateTimeInterface $date
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws ServiceAction\Create
*/
public function import(int $projectId, DateTimeInterface $date, UploadedFileInterface $uploadedFile): array
{
$pricesData = $this->importService->importData($projectId, $date, $uploadedFile);
$prices = [];
foreach ($pricesData as $data) {
try {
$price = $this->precioRepository->create($data);
$price = $this->precioRepository->save($price);
$prices[] = $price;
} catch (EmptyResult | PDOException $exception) {
$this->logger->error('Problemas para agregar precio', ['data' => $data, 'exception' => $exception]);
}
}
foreach ($prices as $price) {
$idx = array_search($price->unidad->id, array_column($pricesData, 'unidad'));
$row = $pricesData[$idx];
try {
$this->estadoPrecioService->replacePrices($price->unidad, $date, $price);
} catch (ServiceAction\Update $exception) {
$this->logger->error('Problemas para reemplazar precios', [
'data' => $row,
'exception' => $exception
]);
}
try {
$this->estadoPrecioService->updatePrice($price, $row['fecha']);
} catch (ServiceAction\Update $exception) {
$this->logger->error('Problemas para actualizar estado de precio', [
'data' => $row,
'exception' => $exception
]);
}
}
return $prices;
}
}

View File

@ -1,89 +0,0 @@
<?php
namespace Incoviba\Service\Venta\Precio;
use DateTimeInterface;
use Incoviba\Model\Venta\Precio;
use Incoviba\Model\Venta\Unidad;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Exception\ServiceAction;
use Incoviba\Model;
use Incoviba\Repository;
class Estado extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Precio $precioRepository,
protected Repository\Venta\EstadoPrecio $estadoPrecioRepository,
protected Repository\Venta\TipoEstadoPrecio $tipoEstadoPrecioRepository)
{
parent::__construct($logger);
}
/**
* @param Model\Venta\Precio $price
* @param DateTimeInterface $date
* @return void
* @throws ServiceAction\Update
*/
public function updatePrice(Model\Venta\Precio $price, DateTimeInterface $date): void
{
try {
$tipoEstado = $this->tipoEstadoPrecioRepository->fetchByDescripcion('vigente');
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
$data = [
'precio' => $price->id,
'fecha' => $date->format('Y-m-d'),
'estado' => $tipoEstado->id
];
try {
$estado = $this->estadoPrecioRepository->create($data);
$this->estadoPrecioRepository->save($estado);
} catch (Implement\Exception\EmptyResult | PDOException $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
}
/**
* @param Unidad $unidad
* @param DateTimeInterface $date
* @param Precio $price
* @return void
* @throws ServiceAction\Update
*/
public function replacePrices(Model\Venta\Unidad $unidad, DateTimeInterface $date, Model\Venta\Precio $price): void
{
try {
$tipoEstado = $this->tipoEstadoPrecioRepository->fetchByDescripcion('reemplazado');
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
try {
$precios = $this->precioRepository->fetchByUnidad($unidad->id);
foreach ($precios as $p) {
if ($p->id === $price->id) {
continue;
}
try {
$estado = $this->estadoPrecioRepository->fetchCurrentByPrecio($p->id);
if ($estado->tipoEstadoPrecio->id === $tipoEstado->id) {
continue;
}
$data = [
'precio' => $p->id,
'estado' => $tipoEstado->id,
'fecha' => $date->format('Y-m-d')
];
$estado = $this->estadoPrecioRepository->create($data);
$this->estadoPrecioRepository->save($estado);
} catch (Implement\Exception\EmptyResult) {}
}
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
}
}

View File

@ -1,243 +0,0 @@
<?php
namespace Incoviba\Service\Venta\Precio;
use DateTime;
use DateTimeInterface;
use PDOException;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction;
use Incoviba\Model;
use Incoviba\Service;
use Incoviba\Repository;
class Import extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Precio $precioRepository,
protected Repository\Inmobiliaria $inmobiliariaRepository,
protected Repository\Proyecto $proyectoRepository,
protected Repository\Venta\Unidad $unidadRepository,
protected Service\FileUpload $fileUploadService)
{
parent::__construct($logger);
}
/**
* @param int $projectId
* @param DateTimeInterface $date
* @param UploadedFileInterface $uploadedFile
* @return array
* @throws ServiceAction\Create
*/
public function importData(int $projectId, DateTimeInterface $date, UploadedFileInterface $uploadedFile): array
{
try {
$data = $this->fileUploadService->getData($uploadedFile);
} catch (ServiceAction\Read $exception) {
throw new ServiceAction\Create(__CLASS__, $exception);
}
$mappedData = $this->mapData($data, $projectId, $date);
$pricesData = [];
foreach ($mappedData as $row) {
$pricesData[] = [
'unidad' => $row['unidad'],
'valor' => $row['precio'],
'fecha' => $row['fecha']
];
}
try {
$priceUnitIds = array_map(fn($price) => $price['unidad'], $pricesData);
$prices = $this->precioRepository->fetchVigentesByUnidades($priceUnitIds);
$priceUnitIds = array_map(fn(array $p) => $p['id'], $prices);
$pricePrices = array_map(fn(array $p) => $p['precio']->valor, $prices);
return array_filter($pricesData, function($price) use ($priceUnitIds, $pricePrices) {
$idx = array_search($price['unidad'], $priceUnitIds);
if ($idx === false) {
return true;
}
return $pricePrices[$idx] !== $price['valor'];
});
} catch (EmptyResult $exception) {
throw new ServiceAction\Create(__CLASS__, $exception);
}
}
protected array $realTitlesMap;
protected function extractTitlesFromData(array $data): array
{
if (isset($this->realTitlesMap)) {
return $this->realTitlesMap;
}
$baseTitlesMap = [
'proyecto' => [],
'precio' => [],
'unidad' => ['departamento'],
'tipo' => ['tipo unidad'],
'fecha' => []
];
$realTitlesMap = [];
$titles = array_keys($data[0]);
foreach ($baseTitlesMap as $base => $optionals) {
foreach ($titles as $title) {
if (str_contains($title, $base)) {
$realTitlesMap[$title] = $base;
break;
}
foreach ($optionals as $optional) {
if (str_contains($title, $optional)) {
$realTitlesMap[$title] = $base;
break;
}
}
}
}
return $this->realTitlesMap = $realTitlesMap;
}
protected function mapData(array $data, int $projectId, DateTimeInterface $date): array
{
$mappedData = $this->mapTitles($data);
$mappedData = $this->mapProjects($mappedData, $projectId);
$mappedData = $this->mapUnits($mappedData);
return $this->mapDates($mappedData, $date);
}
protected function mapTitles(array $data): array
{
$titlesMap = $this->extractTitlesFromData($data);
$mappedData = [];
foreach ($data as $row) {
$mappedData []= $this->mapRow($row, $titlesMap);
}
return $mappedData;
}
protected function mapProjects(array $data, int $projectId): array
{
if (!array_key_exists('proyecto', $data[0])) {
return array_map(function($row) use ($projectId) {
$row['proyecto'] = $projectId;
return $row;
},$data);
}
$projects = $this->extractProjectsFromData($data);
$mappedData = [];
foreach ($data as $row) {
$mappedRow = $row;
$mappedRow['proyecto'] = $projects[$row['proyecto']]?->id ?? $projectId;
$mappedData []= $mappedRow;
}
return $mappedData;
}
protected function mapUnits(array $data): array
{
if (!array_key_exists('unidad', $data[0]) or !array_key_exists('tipo', $data[0])) {
return $data;
}
$unidades = [];
$mappedData = [];
foreach ($data as $row) {
if (!isset($unidades[$row['proyecto']])) {
$unidades[$row['proyecto']] = $this->unidadRepository->fetchByProyecto($row['proyecto']);
}
$tipo = $this->mapTipoUnidad($row['tipo']);
$unidad = array_filter($unidades[$row['proyecto']], function(Model\Venta\Unidad $unidad) use ($row, $tipo) {
return $unidad->descripcion == $row['unidad']
and $unidad->proyectoTipoUnidad->tipoUnidad->descripcion == $tipo;
});
if (count($unidad) === 0) {
$this->logger->warning('Unidad no encontrada', ['row' => $row]);
continue;
}
$mappedRow = $row;
$mappedRow['unidad'] = array_shift($unidad)->id;
unset($mappedRow['tipo']);
$mappedData []= $mappedRow;
}
return $mappedData;
}
protected function mapDates(array $data, DateTimeInterface $date): array
{
if (!array_key_exists('fecha', $data[0])) {
return array_map(function($row) use ($date) {
$row['fecha'] = $date;
return $row;
}, $data);
}
$mappedData = [];
foreach ($data as $row) {
$mappedRow = $row;
$newDate = DateTime::createFromFormat('d/m/Y', $row['fecha']);
$mappedRow['fecha'] = $newDate;
if ($newDate === false) {
$mappedRow['fecha'] = $date;
}
$mappedData []= $mappedRow;
}
return $mappedData;
}
protected function mapRow(array $row, array $titlesMap): array
{
$mappedRow = [];
foreach ($row as $key => $value) {
$mappedRow[$titlesMap[$key]] = $value;
}
return $mappedRow;
}
protected function mapTipoUnidad(string $tipo): string
{
if (str_contains(mb_strtolower($tipo), 'bod')) {
return 'bodega';
}
if (str_contains(mb_strtolower($tipo), 'est')) {
return 'estacionamiento';
}
if (str_contains(mb_strtolower($tipo), 'terr')) {
return 'terraza';
}
return 'departamento';
}
protected array $projectsMap;
protected function extractProjectsFromData(array $data): array
{
if (isset($this->projectsMap)) {
return $this->projectsMap;
}
$projectNames = array_unique(array_map(fn($row) => $row['proyecto'], $data));
$projects = [];
foreach ($projectNames as $projectName) {
try {
$projects[$projectName] = $this->proyectoRepository->fetchByName($projectName);
} catch (EmptyResult $exception) {
try {
$inm = $this->inmobiliariaRepository->fetchByName($projectName);
$inmProjects = $this->proyectoRepository->fetchByInmobiliaria($inm->rut);
$projects[$projectName] = $inmProjects[0];
} catch (EmptyResult $exception2) {
$this->logger->warning('Neither Project nor Society found', [
'projectName' => $projectName,
'exceptions' => [
[
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'data' => $exception->getData(),
'trace' => $exception->getTraceAsString()
],
[
'code' => $exception2->getCode(),
'message' => $exception2->getMessage(),
'file' => $exception2->getFile(),
'line' => $exception2->getLine(),
'data' => $exception2->getData(),
'trace' => $exception2->getTraceAsString()
]
],
]);
}
}
}
return $this->projectsMap = $projects;
}
}

View File

@ -1,24 +1,22 @@
<?php
namespace Incoviba\Service\Venta;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal\Service;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service\Valor;
use Incoviba\Model;
use PDOException;
use Psr\Log\LoggerInterface;
class Propietario extends Service
{
public function __construct(
LoggerInterface $logger,
protected Repository\Venta\Propietario $propietarioRepository,
protected Repository\Direccion $direccionRepository,
protected Valor $valorService
protected Repository\Direccion $direccionRepository
) {
parent::__construct($logger);
}
@ -51,9 +49,6 @@ class Propietario extends Service
$data['direccion'] = $direccion->id;
}
$filteredData = $this->propietarioRepository->filterData($data);
if (array_key_exists('telefono', $filteredData)) {
$filteredData['telefono'] = $this->valorService->telefono()->toDatabase($filteredData['telefono']);
}
try {
return $this->propietarioRepository->edit($propietario, $filteredData);
} catch (PDOException | EmptyResult $exception) {
@ -90,10 +85,6 @@ class Propietario extends Service
]);
$filtered_data = array_intersect_key($data, $fields);
if (array_key_exists('telefono', $filtered_data)) {
$filtered_data['telefono'] = $this->valorService->telefono()->toDatabase($filtered_data['telefono']);
}
try {
$propietario = $this->propietarioRepository->fetchById($data['rut']);
$edits = [];
@ -104,7 +95,6 @@ class Propietario extends Service
} catch (EmptyResult) {
try {
$propietario = $this->propietarioRepository->create($filtered_data);
$this->logger->info('Propietario', ['propietario' => $propietario]);
$propietario = $this->propietarioRepository->save($propietario);
} catch (PDOException $exception) {
throw new Create(__CLASS__, $exception);

View File

@ -1,101 +0,0 @@
<?php
namespace Incoviba\Test\Service\MQTT;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
use xobotyi\beansclient\BeansClient;
use xobotyi\beansclient\Connection;
use xobotyi\beansclient\Exception\JobException;
use xobotyi\beansclient\Job;
use Incoviba\Exception\MQTT\MissingJob;
use Incoviba\Service\MQTT\Beanstalkd;
class BeanstalkdTest extends TestCase
{
protected LoggerInterface $logger;
protected BeansClient $client;
protected function setUp(): void
{
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$this->client = $this->getMockBuilder(BeansClient::class)->disableOriginalConstructor()->getMock();
}
public function testExists(): void
{
$stats = ['current-jobs-ready' => 1];
$this->client->method('watchTube')->willReturn($this->client);
$this->client->method('statsTube')->willReturn($stats);
$service = new Beanstalkd($this->logger, $this->client);
$this->assertTrue($service->exists());
}
public function testNotExists(): void
{
$stats = ['current-jobs-ready' => 0];
$this->client->method('watchTube')->willReturn($this->client);
$this->client->method('statsTube')->willReturn($stats);
$service = new Beanstalkd($this->logger, $this->client);
$this->assertFalse($service->exists());
}
public function testGet(): void
{
$jobData = [
'id' => 1,
'configuration' => [
'type' => 'service',
],
'created_at' => '2020-01-01 00:00:00',
];
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$connection->method('isActive')->willReturn(true);
$this->client->method('getConnection')->willReturn($connection);
$this->client->method('watchTube')->willReturn($this->client);
$this->client->method('statsTube')->willReturn(['current-jobs-ready' => 1]);
$job = new Job($this->client, 1, 'ready', json_encode($jobData));
$this->client->method('reserve')->willReturn($job);
$service = new Beanstalkd($this->logger, $this->client);
$this->assertEquals(json_encode($jobData), $service->get());
}
public function testGetException(): void
{
$this->client->method('watchTube')->willReturn($this->client);
$this->client->method('statsTube')->willReturn(['current-jobs-ready' => 0]);
$service = new Beanstalkd($this->logger, $this->client);
$this->expectException(MissingJob::class);
$service->get();
$this->client->method('statsTube')->willReturn(['current-jobs-ready' => 1]);
$exception = new JobException();
$this->client->method('reserve')->willThrowException($exception);
$this->expectException(MissingJob::class);
$service->get();
}
public function testSet(): void
{
$this->client->method('useTube')->willReturn($this->client);
$this->client->method('put');
$service = new Beanstalkd($this->logger, $this->client);
$service->set('test');
$this->assertTrue(true);
}
public function testSetException(): void
{
$this->client->method('useTube')->willReturn($this->client);
$exception = new JobException();
$this->client->method('put')->willThrowException($exception);
$service = new Beanstalkd($this->logger, $this->client);
$service->set('test');
$this->assertTrue(true);
}
public function testRemove(): void
{
$this->client->method('useTube')->willReturn($this->client);
$this->client->method('delete')->willReturn(true);
$service = new Beanstalkd($this->logger, $this->client);
$service->remove(1);
$this->assertTrue(true);
$this->client->method('delete')->willReturn(false);
$service->remove(1);
$this->assertTrue(true);
}
}

View File

@ -1,69 +0,0 @@
<?php
namespace Incoviba\Test\Service;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
use xobotyi\beansclient\BeansClient;
use Incoviba\Exception\MQTT\MissingClient;
use Incoviba\Service\MQTT;
use Incoviba\Service\MQTT\Beanstalkd;
class MQTTTest extends TestCase
{
public function testRegisterAndClientExistsAndGet(): void
{
$mqtt = new MQTT();
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
$mqtt->register('beanstalkd', $beanstalkd);
$this->assertTrue($mqtt->clientExists('beanstalkd'));
}
public function testGetClient(): void
{
$mqtt = new MQTT();
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
$client = $this->getMockBuilder(BeansClient::class)->disableOriginalConstructor()->getMock();
$beanstalkd = new Beanstalkd($logger, $client);
$mqtt->register('beanstalkd', $beanstalkd);
$this->assertEquals($beanstalkd, $mqtt->getClient('beanstalkd'));
}
public function testGetClientException(): void
{
$mqtt = new MQTT();
$this->expectException(MissingClient::class);
$mqtt->getClient('test');
}
public function testExists(): void
{
$mqtt = new MQTT();
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
$beanstalkd->method('exists')->willReturn(true);
$mqtt->register('beanstalkd', $beanstalkd);
$this->assertTrue($mqtt->exists('beanstalkd'));
}
public function testGet(): void
{
$mqtt = new MQTT();
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
$beanstalkd->method('get')->willReturn('test');
$mqtt->register('beanstalkd', $beanstalkd);
$this->assertEquals('test', $mqtt->get('beanstalkd'));
}
public function testSet(): void
{
$mqtt = new MQTT();
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
$beanstalkd->method('set');
$mqtt->register('beanstalkd', $beanstalkd);
$mqtt->set('test', 0, 'beanstalkd');
$this->assertTrue(true);
}
public function testRemove(): void
{
$mqtt = new MQTT();
$beanstalkd = $this->getMockBuilder(Beanstalkd::class)->disableOriginalConstructor()->getMock();
$beanstalkd->method('remove');
$mqtt->register('beanstalkd', $beanstalkd);
$mqtt->remove(0, 'beanstalkd');
$this->assertTrue(true);
}
}

View File

@ -1,66 +0,0 @@
<?php
namespace Incoviba\Test\Service;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
use Incoviba\Service\Job;
use Incoviba\Service\Queue;
use Incoviba\Service\Worker;
use Incoviba\Model;
class QueueTest extends TestCase
{
protected LoggerInterface $logger;
protected Job $jobService;
protected Worker $defaultWorker;
protected function setUp(): void
{
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->jobService = $this->getMockBuilder(Job::class)
->disableOriginalConstructor()
->getMock();
$this->defaultWorker = $this->getMockBuilder(Worker::class)
->disableOriginalConstructor()
->getMock();
}
public function testRegister(): void
{
$queue = new Queue($this->logger, $this->jobService, $this->defaultWorker);
$worker = $this->getMockBuilder(Worker::class)
->disableOriginalConstructor()
->getMock();
$queue->register('test', $worker);
$this->assertTrue(true);
}
public function testEnqueue(): void
{
$queue = new Queue($this->logger, $this->jobService, $this->defaultWorker);
$jobData = ['test' => 'test'];
$result = $queue->enqueue($jobData);
$this->assertTrue($result);
$result = $queue->push($jobData);
$this->assertTrue($result);
}
public function testRun(): void
{
$queue = new Queue($this->logger, $this->jobService, $this->defaultWorker);
$result = $queue->run();
$this->assertTrue($result);
$jobData = [
'type' => 'test',
];
$job = new Model\Job();
$job->id = 1;
$job->configuration = $jobData;
$this->jobService->method('isPending')->willReturn(true);
$this->jobService->method('get')->willReturn($job);
$result = $queue->run();
$this->assertTrue($result);
}
}

View File

@ -1,164 +0,0 @@
<?php
namespace Incoviba\Test\Unit\Service\Venta\Precio;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
use Faker;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class EstadoTest extends TestCase
{
protected LoggerInterface $logger;
protected Repository\Venta\Precio $precioRepository;
protected Repository\Venta\EstadoPrecio $estadoPrecioRepository;
protected Repository\Venta\TipoEstadoPrecio $tipoEstadoPrecioRepository;
protected function setUp(): void
{
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->precioRepository = $this->getMockBuilder(Repository\Venta\Precio::class)
->disableOriginalConstructor()
->getMock();
$this->estadoPrecioRepository = $this->getMockBuilder(Repository\Venta\EstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$this->tipoEstadoPrecioRepository = $this->getMockBuilder(Repository\Venta\TipoEstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
}
public function testUpdatePrice(): void
{
$uniqueElements = 1000;
$faker = Faker\Factory::create();
$tipoEstadoPrecio = $this->getMockBuilder(Model\Venta\TipoEstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$tipoEstadoPrecio->id = $faker->unique()->numberBetween(1, $uniqueElements);
$tipoEstadoPrecio->descripcion = 'vigente';
$tipoEstadoPrecioRepository = $this->getMockBuilder(Repository\Venta\TipoEstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$tipoEstadoPrecioRepository->method('fetchByDescripcion')->with('vigente')->willReturn($tipoEstadoPrecio);
$unidad = $this->getMockBuilder(Model\Venta\Unidad::class)
->disableOriginalConstructor()
->getMock();
$unidad->id = $faker->unique()->numberBetween(1, $uniqueElements);
$precio = $this->getMockBuilder(Model\Venta\Precio::class)
->disableOriginalConstructor()
->getMock();
$precio->id = $faker->unique()->numberBetween(1, $uniqueElements);
$precio->unidad = $unidad;
$estadoPrecio = $this->getMockBuilder(Model\Venta\EstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$estadoPrecio->id = $faker->unique()->numberBetween(1, $uniqueElements);
$estadoPrecio->precio = $precio;
$estadoPrecio->tipoEstadoPrecio = $tipoEstadoPrecio;
$estadoPrecioRepository = $this->getMockBuilder(Repository\Venta\EstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$estadoPrecioRepository->method('create')->willReturn($estadoPrecio);
$estadoPrecioRepository->method('save')->willReturnArgument(0);
$date = $faker->dateTimeBetween('-6 months');
$estadoPrecioService = new Service\Venta\Precio\Estado($this->logger, $this->precioRepository,
$estadoPrecioRepository, $tipoEstadoPrecioRepository);
$estadoPrecioService->updatePrice($precio, $date);
$this->assertTrue(true);
}
public function testReplacePrices(): void
{
$uniqueElements = 1000;
$faker = Faker\Factory::create();
$tipoEstadoPrecio1 = $this->getMockBuilder(Model\Venta\TipoEstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$tipoEstadoPrecio1->id = $faker->unique()->numberBetween(1, $uniqueElements);
$tipoEstadoPrecio1->descripcion = 'vigente';
$tipoEstadoPrecio = $this->getMockBuilder(Model\Venta\TipoEstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$tipoEstadoPrecio->id = $faker->unique()->numberBetween(1, $uniqueElements);
$tipoEstadoPrecio->descripcion = 'reemplazado';
$this->tipoEstadoPrecioRepository->method('fetchByDescripcion')
->willReturnCallback(function($descripcion) use ($tipoEstadoPrecio, $tipoEstadoPrecio1) {
return match ($descripcion) {
'vigente' => $tipoEstadoPrecio1,
'reemplazado' => $tipoEstadoPrecio,
};
});
$unidad = $this->getMockBuilder(Model\Venta\Unidad::class)
->disableOriginalConstructor()
->getMock();
$unidad->id = $faker->unique()->numberBetween(1, $uniqueElements);
$preciosCount = $faker->numberBetween(1, 10);
$precios = [];
$estados = [];
for ($i = 0; $i < $preciosCount; $i++) {
$precio = $this->getMockBuilder(Model\Venta\Precio::class)
->disableOriginalConstructor()
->getMock();
$precio->id = $faker->unique()->numberBetween(1, $uniqueElements);
$precios []= $precio;
$estado = $this->getMockBuilder(Model\Venta\EstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$estado->id = $faker->unique()->numberBetween(1, $uniqueElements);
$estado->precio = $precio;
$estado->tipoEstadoPrecio = $tipoEstadoPrecio1;
$estados []= $estado;
}
$this->precioRepository->method('fetchByUnidad')->with($unidad->id)->willReturn($precios);
$this->estadoPrecioRepository->method('fetchCurrentByPrecio')->willReturnCallback(function($precio_id) use ($estados) {
$idx = array_search($precio_id, array_map(fn($estado) => $estado->precio->id, $estados));
return $estados[$idx];
});
$newEstados = [];
foreach ($precios as $precio) {
$estado = $this->getMockBuilder(Model\Venta\EstadoPrecio::class)
->disableOriginalConstructor()
->getMock();
$estado->id = $faker->unique()->numberBetween(1, $uniqueElements);
$estado->precio = $precio;
$estado->tipoEstadoPrecio = $tipoEstadoPrecio;
$newEstados []= $estado;
}
$this->estadoPrecioRepository->method('create')->willReturnCallback(function($data) use ($newEstados) {
$idx = array_search($data['precio'], array_map(fn($estado) => $estado->precio->id, $newEstados));
return $newEstados[$idx];
});
$this->estadoPrecioRepository->method('save')->willReturnArgument(0);
$precio = $this->getMockBuilder(Model\Venta\Precio::class)
->disableOriginalConstructor()
->getMock();
$precio->id = $faker->unique()->numberBetween(1, $uniqueElements);
$precio->unidad = $unidad;
$date = $faker->dateTimeBetween('-6 months');
$estadoPrecioService = new Service\Venta\Precio\Estado($this->logger, $this->precioRepository,
$this->estadoPrecioRepository, $this->tipoEstadoPrecioRepository);
$estadoPrecioService->replacePrices($unidad, $date, $precio);
$this->assertTrue(true);
}
}

View File

@ -1,2 +1,2 @@
[www]
pm.max_children = 8
pm.max_children = 15

View File

@ -2,12 +2,10 @@
"name": "incoviba/cli",
"type": "project",
"require": {
"ext-sockets": "*",
"dragonmantank/cron-expression": "^3.4",
"guzzlehttp/guzzle": "^7.8",
"hollodotme/fast-cgi-client": "^3.1",
"monolog/monolog": "^3.5",
"pda/pheanstalk": "^7.0",
"php-di/php-di": "^7.0",
"predis/predis": "^3.0",
"symfony/console": "^6.3"

View File

@ -7,5 +7,5 @@
0 2 * * * /code/bin/incoviba money:uf >> /logs/commands 2>&1
0 2 * * * /code/bin/incoviba money:uf:update >> /logs/commands 2>&1
0 2 1 * * /code/bin/incoviba money:ipc >> /logs/commands 2>&1
*/1 * * * * /code/bin/incoviba queue >> /logs/commands 2>&1
*/2 * * * * /code/bin/incoviba queue >> /logs/commands 2>&1
0 3 * * * /code/bin/incoviba external:services >> /logs/commands 2>&1

9
cli/entrypoint Executable file → Normal file
View File

@ -6,13 +6,8 @@ then
then
CMD=$1
shift
if [[ $# -gt 0 ]]
then
$CMD -c "$@"
exit 0
fi
$CMD
exit 0
$CMD -c "$@"
exit
fi
fi

View File

@ -16,15 +16,4 @@ return [
}
return new Predis\Client($options);
},
Pheanstalk\Pheanstalk::class => function(ContainerInterface $container) {
return Pheanstalk\Pheanstalk::create(
$container->get('BEANSTALKD_HOST'),
$container->has('BEANSTALKD_PORT') ? $container->get('BEANSTALKD_PORT') : 11300
);
},
Incoviba\Service\MQTT\MQTTInterface::class => function(ContainerInterface $container) {
$service = new Incoviba\Service\MQTT($container->get(Psr\Log\LoggerInterface::class));
$service->register('default', $container->get(Incoviba\Service\MQTT\Pheanstalk::class));
return $service;
}
];

View File

@ -37,8 +37,6 @@ class BaseLoop extends Console\Command\Command
foreach ($commands as $command) {
$this->runCommand($input, $output, $command);
}
unset($commands);
memory_reset_peak_usage();
$this->waitNextTimeout($output, $start);
}
return self::SUCCESS;

View File

@ -0,0 +1,48 @@
<?php
namespace Incoviba\Command\Job;
use Symfony\Component\Console;
use Incoviba\Service;
#[Console\Attribute\AsCommand(name: 'jobs:pending', description: 'List pending jobs')]
class Pending extends Console\Command\Command
{
public function __construct(protected Service\Job $jobService, ?string $name = null)
{
parent::__construct($name);
}
protected function configure(): void
{
$this->addOption('full', 'f', Console\Input\InputOption::VALUE_NONE, 'Full output');
}
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
{
$jobs = $this->jobService->getPending();
$jobCount = count($jobs);
$output->writeln("Found {$jobCount} pending jobs");
if ($input->getOption('full') and $jobCount > 0) {
$io = new Console\Style\SymfonyStyle($input, $output);
$rows = [];
foreach ($jobs as $job) {
$retries = $job['retries'] ?? 0;
$updated = $job['updated_at'] ?? '';
$rows[] = [
$job['id'],
$job['created_at'],
$job['configuration']['type'],
$retries,
$updated
];
}
$io->table(['ID', 'Created', 'Type', 'Retries', 'Updated'], $rows);
}
return self::SUCCESS;
}
}

View File

@ -9,16 +9,22 @@ use Incoviba\Service;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console;
#[Console\Attribute\AsCommand(name: 'jobs:run', description: 'Run job')]
#[Console\Attribute\AsCommand(name: 'jobs:run', description: 'Run jobs')]
class Run extends Console\Command\Command
{
public function __construct(protected Service\FastCGI $fastcgi, protected LoggerInterface $logger,
protected Service\Job $jobService,
protected DateTimeZone $timeZone, ?string $name = null)
{
parent::__construct($name);
}
protected function configure(): void
{
$this->addArgument('job_ids',
Console\Input\InputArgument::IS_ARRAY | Console\Input\InputArgument::REQUIRED, 'Job IDs');
}
protected array $output = [];
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
{
try {
@ -27,18 +33,44 @@ class Run extends Console\Command\Command
$now = new DateTimeImmutable();
}
if ($this->jobService->getPending() === 0) {
$output->writeln("[{$now->format('Y-m-d H:i:s e')}] No pending jobs to run.");
return self::SUCCESS;
}
$jobIds = $input->getArgument('job_ids');
$jobCount = count($jobIds);
$output->writeln("[{$now->format('Y-m-d H:i:s e')}] Running Ready Job...");
$this->runJob();
return $this->getResponses();
$this->pushOutput('top', ['message' => "[{$now->format('Y-m-d H:i:s e')}] Running {$jobCount} jobs..."]);
$this->pushOutput('bottom', ['table' => [
['Job IDs'],
array_map(function($row) {return [$row];},$jobIds)
]]);
$this->pushOutput('top', ['progress' => $jobCount]);
$result = $this->runJobs($jobIds);
$this->pushOutput('top', ['progress' => 'finish']);
$this->writeOutput($input, $output);
return $result;
}
protected function runJob(): bool
protected function runJobs(array $jobIds): int
{
$uri = "/api/queue/run";
$pendingJobs = [];
foreach ($jobIds as $jobId) {
if (!$this->runJob($jobId)) {
$pendingJobs []= $jobId;
}
}
$result = $this->getResponses();
if (count($pendingJobs) > 0) {
if ($this->runJobs($pendingJobs) === self::FAILURE) {
$result = self::FAILURE;
}
}
return $result;
}
protected function runJob(int $jobId): bool
{
$uri = "/api/queue/run/{$jobId}";
$this->pushOutput('bottom', ['message' => "GET {$uri}"]);
try {
$this->fastcgi->get($uri);
@ -53,6 +85,7 @@ class Run extends Console\Command\Command
$result = self::SUCCESS;
$responses = $this->fastcgi->awaitResponses();
foreach ($responses as $response) {
$this->pushOutput('top', ['progress' => 'advance']);
if ($response->getError() !== '') {
$this->logger->error("Error running job", [
'error' => $response->getError(),
@ -60,8 +93,100 @@ class Run extends Console\Command\Command
'headers' => $response->getHeaders(),
]);
$result = self::FAILURE;
continue;
}
$this->pushOutput('bottom', ['message' => $response->getBody()]);
}
return $result;
}
protected function pushOutput(string $section, array $configuration): void
{
if (!isset($this->output[$section])) {
$this->output[$section] = [];
}
foreach ($configuration as $key => $value) {
if (!isset($this->output[$section][$key])) {
$this->output[$section][$key] = [];
}
$this->output[$section][$key] []= $value;
}
if (isset($this->output[$section]['progress'])) {
usort($this->output[$section]['progress'], function($a, $b) {
if ($a === $b) {
return 0;
}
if (is_int($a)) {
return -1;
}
if (is_int($b)) {
return 1;
}
if ($a === 'finish') {
return 1;
}
if ($b === 'finish') {
return -1;
}
return 0;
});
}
}
protected function writeOutput(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): void
{
$sectionNames = array_keys($this->output);
$ios = [];
foreach ($sectionNames as $sectionName) {
$section = $output->section();
$ios[$sectionName] = new Console\Style\SymfonyStyle($input, $section);
}
foreach ($this->output as $sectionName => $configurations) {
$io = $ios[$sectionName];
$this->writeSection($io, $configurations);
}
}
protected function writeSection(Console\Style\SymfonyStyle $io, array $configurations): void
{
if (array_key_exists('table', $configurations)) {
$this->writeTables($io, $configurations['table']);
}
if (array_key_exists('progress', $configurations)) {
$this->writeProgress($io, $configurations['progress']);
}
if (array_key_exists('message', $configurations)) {
$this->writeMessages($io, $configurations['message']);
}
}
protected function writeTables(Console\Style\SymfonyStyle $io, array $tableConfigurations): void
{
foreach ($tableConfigurations as $tableData) {
$io->table(...$tableData);
}
}
protected function writeMessages(Console\Style\SymfonyStyle $io, array $messages): void
{
foreach ($messages as $message) {
$io->writeln($message);
}
}
protected function writeProgress(Console\Style\SymfonyStyle $io, array $progresses): void
{
$progressBar = null;
foreach ($progresses as $progress) {
if ($progress === 'advance' and $progressBar !== null) {
$progressBar->advance();
continue;
}
if ($progress === 'finish' and $progressBar !== null) {
$progressBar->finish();
continue;
}
if (in_array($progress, ['finish', 'advance'])) {
continue;
}
$progressBar = $io->createProgressBar($progress);
}
$io->newLine();
}
}

View File

@ -35,29 +35,61 @@ class Queue extends Command
];
$io = new Console\Style\SymfonyStyle($input, $this->sections['top']);
$now = new DateTimeImmutable('now', $this->timezone);
if ($this->jobService->getPending() === 0) {
$io->success("[{$now->format('Y-m-d H:i:s e')}] Queue is empty");
return self::SUCCESS;
}
$io->title("[{$now->format('Y-m-d H:i:s e')}] Running Queue...");
$results = [];
for ($i = 0; $i < $this->batchSize; $i++) {
if ($this->jobService->getPending() === 0) {
break;
}
$results []= $this->runJob();
$jobs = $this->getJobs();
$jobCount = count($jobs);
if ($jobCount === 0) {
return Console\Command\Command::SUCCESS;
}
return count(array_filter($results, fn ($result) => $result === self::FAILURE)) === 0 ? self::SUCCESS : self::FAILURE;
$io->writeln("Found {$jobCount} jobs to run");
$result = $this->runJobs($io, $jobs);
foreach ($this->outputs as $output) {
$this->sections['bottom']->writeln($output);
}
return $result;
}
protected array $sections;
protected function getJobs(): array
{
$this->logger->debug("Getting jobs");
$jobs = $this->jobService->getPending();
$jobCount = count($jobs);
if ($jobCount === 0) {
$this->logger->debug("No jobs to run");
return [];
}
$this->logger->debug("Found {$jobCount} jobs");
return array_column($jobs, 'id');
}
protected function runJobs(Console\Style\SymfonyStyle $io, array $jobs): int
{
$chunks = array_chunk($jobs, $this->batchSize);
$chunkCount = count($chunks);
$result = self::SUCCESS;
$progress1 = $io->createProgressBar($chunkCount);
$progress1->start();
foreach ($chunks as $chunk) {
if ($this->runJobBatch($chunk) === self::FAILURE) {
$result = self::FAILURE;
}
$progress1->advance();
}
$progress1->finish();
return $result;
}
protected array $outputs = [];
protected function runJob(): int
protected function runJobBatch(array $jobIds): int
{
$baseCommand = "{$this->baseCommand} jobs:run";
$command = "{$baseCommand}";
$jobsLine = implode(' ', $jobIds);
$command = "{$baseCommand} {$jobsLine}";
try {
exec($command, $output, $resultCode);
$this->outputs []= $output;
@ -74,8 +106,7 @@ class Queue extends Command
'result_code' => $resultCode
]);
return self::FAILURE;
} else {
return self::SUCCESS;
}
return self::SUCCESS;
}
}

View File

@ -1,22 +0,0 @@
<?php
namespace Incoviba\Command\Queue;
use Incoviba\Service;
use Symfony\Component\Console;
#[Console\Attribute\AsCommand(name: 'queue:pending', description: 'List pending jobs in queue')]
class Pending extends Console\Command\Command
{
public function __construct(protected Service\Job $jobService, ?string $name = null)
{
parent::__construct($name);
}
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
{
$jobCount = $this->jobService->getPending();
$output->writeln("Found {$jobCount} pending jobs");
return self::SUCCESS;
}
}

View File

@ -2,22 +2,20 @@
namespace Incoviba\Command\Queue;
use Throwable;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console;
use Incoviba\Service;
#[Console\Attribute\AsCommand(name: 'queue:push', description: 'Push a job to the queue')]
class Push extends Console\Command\Command
{
public function __construct(protected LoggerInterface $logger, protected Service\Job $jobService, ?string $name = null)
public function __construct(protected Service\Job $jobService, ?string $name = null)
{
parent::__construct($name);
}
protected function configure(): void
{
$this->addOption('configurations', 'c', Console\Input\InputOption::VALUE_REQUIRED | Console\Input\InputOption::VALUE_IS_ARRAY, 'Job configuration options array, each job configuration must be in valid JSON format');
$this->addOption('files', 'f', Console\Input\InputOption::VALUE_REQUIRED | Console\Input\InputOption::VALUE_IS_ARRAY, 'Paths to jobs configurations files with JSON array content');
$this->addOption('configurations', 'c', Console\Input\InputOption::VALUE_REQUIRED | Console\Input\InputOption::VALUE_IS_ARRAY, 'Job configuration, must be in valid JSON format');
}
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
@ -25,8 +23,8 @@ class Push extends Console\Command\Command
$io = new Console\Style\SymfonyStyle($input, $output);
$io->title("Pushing job");
$configurations = $this->getConfigurations($input);
if (count($configurations) === 0) {
$configurations = $input->getOption('configurations');
if ($configurations === null) {
$io->error('Missing configurations');
return self::FAILURE;
}
@ -48,74 +46,4 @@ class Push extends Console\Command\Command
}
return $result;
}
protected function getConfigurations(Console\Input\InputInterface $input): array
{
return [
...$this->getFilesConfigurations($input),
...$this->getOptionConfigurations($input),
];
}
protected function getFilesConfigurations(Console\Input\InputInterface $input): array
{
$configurations = [];
$files = $input->getOption('files');
if ($files === null) {
return $configurations;
}
foreach ($files as $filePath) {
if (!file_exists($filePath)) {
continue;
}
$configurations = array_merge($configurations, $this->getFileConfigurations($filePath));
}
return $configurations;
}
protected function getFileConfigurations(string $filePath): array
{
$configurations = [];
if (!file_exists($filePath)) {
return $configurations;
}
$json = file_get_contents($filePath);
if (!json_validate($json)) {
return $configurations;
}
$tmp = json_decode($json, true);
foreach ($tmp as $config) {
try {
$configurations []= $this->processConfiguration(json_encode($config));
} catch (Throwable $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception, 'config' => $config]);
}
}
return $configurations;
}
protected function getOptionConfigurations(Console\Input\InputInterface $input): array
{
$configurations = [];
$configOptions = $input->getOption('configurations');
if ($configOptions === null) {
return $configurations;
}
foreach ($configOptions as $config) {
try {
$configurations []= $this->processConfiguration($config);
} catch (Throwable $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception, 'config' => $config]);
}
}
return $configurations;
}
protected function processConfiguration(string $configuration): string
{
$json = json_decode($configuration, true);
if (!array_key_exists('type', $json) and !array_key_exists('configuration', $json)) {
throw new Console\Exception\InvalidArgumentException('Missing type or configuration key in JSON');
}
if (array_key_exists('type', $json)) {
return json_encode($json);
}
return json_encode($json['configuration']);
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace Incoviba\Exception;
use Throwable;
use Exception;
abstract class MQTT extends Exception
{
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
$baseCode = 700;
$code = $baseCode + $code;
if ($message == "") {
$message = "MQTT Exception";
}
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class Create extends MQTT
{
public function __construct(string $tube = '', string $payload = '', ?Throwable $previous = null)
{
$message = "Unable to create MQTT message: {$payload} in tube {$tube}";
$code = 11;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class Delete extends MQTT
{
public function __construct(string $tube, int $jobId, ?Throwable $previous = null)
{
$message = "Could not delete job {$jobId} in tube {$tube}";
$code = 13;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class Read extends MQTT
{
public function __construct(string $tube, ?Throwable $previous = null)
{
$message = "Error reading from tube {$tube}";
$code = 10;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,14 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Incoviba\Exception\MQTT;
use Throwable;
class UnknownTransport extends MQTT
{
public function __construct(string $transportName, ?Throwable $previous = null)
{
$message = "Unknown transport {$transportName}";
parent::__construct($message, 1, $previous);
}
}

View File

@ -1,16 +0,0 @@
<?php
namespace Incoviba\Exception\MQTT;
use Throwable;
use Incoviba\Exception\MQTT;
class Update extends MQTT
{
public function __construct(string $tube, string $payload, ?int $jobId = null, ?Throwable $previous = null)
{
$jobString = $jobId !== null ? " with jobId {$jobId}" : '';
$message = "Could not update job{$jobString} with {$payload} in tube {$tube}";
$code = 12;
parent::__construct($message, $code, $previous);
}
}

View File

@ -1,9 +0,0 @@
<?php
namespace Incoviba;
use Psr\Log\LoggerInterface;
abstract class Service
{
public function __construct(protected LoggerInterface $logger) {}
}

View File

@ -5,22 +5,27 @@ use DateInvalidTimeZoneException;
use DateMalformedStringException;
use DateTimeImmutable;
use DateTimeZone;
use Exception;
use Psr\Log\LoggerInterface;
use Incoviba\Exception\MQTT as MQTTException;
use Incoviba\Service\MQTT\MQTTInterface;
use Predis\Connection\ConnectionException;
class Job
{
public function __construct(protected LoggerInterface $logger, protected MQTTInterface $mqttService) {}
public function __construct(protected LoggerInterface $logger, protected Redis $redisService)
{
$this->redisKey = 'jobs';
}
protected string $redisKey;
public function getPending(): int
public function getPending(): array
{
try {
return $this->mqttService->pending();
} catch (MQTTException $exception) {
$jobs = $this->redisService->get($this->redisKey);
return json_decode($jobs, true);
} catch (ConnectionException|Exception $exception) {
$exception = new Exception("Could not read {$this->redisKey} from Redis", $exception->getCode(), $exception);
$this->logger->warning($exception->getMessage(), ['exception' => $exception]);
return 0;
return [];
}
}
@ -39,11 +44,9 @@ class Job
'updated_at' => null,
'retries' => 0
];
try {
$this->mqttService->set(json_encode($data));
} catch (MQTTException $exception) {
$this->logger->warning($exception->getMessage(), ['exception' => $exception]);
}
$jobs = $this->getPending();
$jobs []= $data;
$this->redisService->set($this->redisKey, json_encode($jobs), -1);
return $data;
}
}

View File

@ -1,124 +0,0 @@
<?php
namespace Incoviba\Service;
use Incoviba\Exception\MQTT as MQTTException;
use Incoviba\Service;
use Incoviba\Service\MQTT\MQTTInterface;
class MQTT extends Service implements MQTTInterface
{
protected array $transports = [];
public function register(string $name, MQTTInterface $transport): self
{
$this->transports[$name] = $transport;
return $this;
}
/**
* @param string $payload
* @param int $delay
* @param string|null $transportName
* @return $this
* @throws MQTTException\UnknownTransport
* @throws MQTTException\Create
*/
public function set(string $payload, int $delay = 0, ?string $transportName = null): self
{
$transport = $this->getTransport($transportName);
$transport->set($payload, $delay);
return $this;
}
/**
* @param string|null $transportName
* @return int
* @throws MQTTException\UnknownTransport
* @throws MQTTException\Read
*/
public function pending(?string $transportName = null): int
{
$transport = $this->getTransport($transportName);
return $transport->pending();
}
/**
* @param int|null $jobId
* @param string|null $transportName
* @return bool
* @throws MQTTException\UnknownTransport
* @throws MQTTException\Read
*/
public function exists(?int $jobId = null, ?string $transportName = null): bool
{
$transport = $this->getTransport($transportName);
return $transport->exists($jobId);
}
/**
* @param int|null $jobId
* @param string|null $transportName
* @return string
* @throws MQTTException\UnknownTransport
* @throws MQTTException\Read
*/
public function get(?int $jobId = null, ?string $transportName = null): string
{
$transport = $this->getTransport($transportName);
return $transport->get($jobId);
}
/**
* @param string $newPayload
* @param int|null $jobId
* @param string|null $transportName
* @return $this
* @throws MQTTException\UnknownTransport
* @throws MQTTException\Update
*/
public function update(string $newPayload, ?int $jobId = null, ?string $transportName = null): self
{
$transport = $this->getTransport($transportName);
$transport->update($newPayload, $jobId);
return $this;
}
/**
* @param int|null $jobId
* @param string|null $transportName
* @return $this
* @throws MQTTException\UnknownTransport
* @throws MQTTException\Delete
*/
public function remove(?int $jobId = null, ?string $transportName = null): self
{
$transport = $this->getTransport($transportName);
$transport->remove($jobId);
return $this;
}
/**
* @param string|null $transportName
* @return mixed
* @throws MQTTException\UnknownTransport
*/
protected function getTransport(?string $transportName): mixed
{
if (count($this->transports) === 0) {
throw new MQTTException\UnknownTransport('');
}
if ($transportName === null) {
if (array_key_exists('default', $this->transports)) {
$transportName = 'default';
} else {
$transportName = array_keys($this->transports)[0];
}
}
if (!array_key_exists($transportName, $this->transports)) {
if ($transportName === null) {
$transportName = '';
}
throw new MQTTException\UnknownTransport($transportName);
}
return $this->transports[$transportName];
}
}

View File

@ -1,127 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Exception;
use Psr\Log\LoggerInterface;
use xobotyi\beansclient;
use Incoviba\Service;
use Incoviba\Exception\MQTT;
class Beanstalkd extends Service implements MQTTInterface
{
const string DEFAULT_TUBE = 'default';
const int DEFAULT_TTR = 30;
const int DEFAULT_PRIORITY = 1_024;
public function __construct(LoggerInterface $logger, protected beansclient\Client $client,
protected string $tube = self::DEFAULT_TUBE,
protected int $ttr = self::DEFAULT_TTR,
protected int $priority = self::DEFAULT_PRIORITY)
{
parent::__construct($logger);
}
/**
* @param string $payload
* @param int $delay
* @return self
* @throws MQTT\Create
*/
public function set(string $payload, int $delay = 60): self
{
try {
$this->client->put($payload, $this->ttr, $this->priority, $delay);
} catch (Exception $exception) {
throw new MQTT\Create($this->tube, $payload, $exception);
}
return $this;
}
/**
* @return int
* @throws MQTT\Read
*/
public function pending(): int
{
try {
$stats = $this->client
->statsTube($this->tube);
} catch (Exception $exception) {
throw new MQTT\Read($this->tube, $exception);
}
if (!array_key_exists('current-jobs-ready', $stats)) {
throw new MQTT\Read($this->tube);
}
return $stats['current-jobs-ready'];
}
/**
* @param int|null $jobId
* @return bool
* @throws MQTT\Read
*/
public function exists(?int $jobId = null): bool
{
return $this->pending() > 0;
}
protected int $currentJobId;
/**
* @param int|null $jobId
* @return string
* @throws MQTT\Read
*/
public function get(?int $jobId = null): string
{
try {
if ($jobId !== null) {
$job = (object) $this->client
->reserveJob($jobId);
} else {
$job = (object) $this->client
->reserve();
}
} catch (Exception $exception) {
throw new MQTT\Read($this->tube, $exception);
}
$this->currentJobId = $job->id;
return $job->payload;
}
/**
* @param string $newPayload
* @param int|null $jobId
* @return self
* @throws MQTT\Update
*/
public function update(string $newPayload, ?int $jobId = null): self
{
try {
$this->remove($jobId);
$this->set($newPayload);
} catch (MQTT\Delete | MQTT\Create $exception) {
throw new MQTT\Update($this->tube, $newPayload, $jobId, $exception);
}
return $this;
}
/**
* @param int|null $jobId
* @return self
* @throws MQTT\Delete
*/
public function remove(?int $jobId = null): self
{
try {
if ($jobId === null) {
$jobId = $this->currentJobId;
}
$this->client
->delete($jobId);
} catch (Exception $exception) {
throw new MQTT\Delete($this->tube, $jobId, $exception);
}
return $this;
}
}

View File

@ -1,12 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
interface MQTTInterface
{
public function set(string $payload, int $delay = 0): self;
public function pending(): int;
public function exists(?int $jobId = null): bool;
public function get(?int $jobId = null): string;
public function update(string $newPayload, ?int $jobId = null): self;
public function remove(?int $jobId = null): self;
}

View File

@ -1,65 +0,0 @@
<?php
namespace Incoviba\Service\MQTT;
use Psr\Log\LoggerInterface;
use Pheanstalk as PBA;
use Incoviba\Service;
class Pheanstalk extends Service implements MQTTInterface
{
public function __construct(LoggerInterface $logger, protected PBA\Pheanstalk $client, string $tubeName = 'default')
{
parent::__construct($logger);
$this->tube = new PBA\Values\TubeName($tubeName);
}
protected PBA\Values\TubeName $tube;
public function set(string $payload, int $delay = 0): self
{
$this->client->useTube($this->tube);
$this->client->put($payload, $delay);
return $this;
}
public function pending(): int
{
$stats = $this->client->statsTube($this->tube);
return $stats->currentJobsReady;
}
public function exists(?int $jobId = null): bool
{
return $this->pending() > 0;
}
protected int $currentJobId;
public function get(?int $jobId = null): string
{
$this->client->watch($this->tube);
if ($jobId !== null) {
$jobId = new PBA\Values\JobId($jobId);
$job = $this->client->reserveJob($jobId);
} else {
$job = $this->client->reserve();
}
$this->currentJobId = $job->getId();
return $job->getData();
}
public function update(string $newPayload, ?int $jobId = null): self
{
$this->remove($jobId);
$this->set($newPayload);
return $this;
}
public function remove(?int $jobId = null): self
{
if ($jobId === null) {
$jobId = $this->currentJobId;
}
$this->client->watch($this->tube);
$this->client->delete(new PBA\Values\JobId($jobId));
return $this;
}
}

View File

@ -1,85 +0,0 @@
<?php
namespace Incoviba\Service;
class SystemInfo
{
public function getAllInfo(): array
{
return [
'memory' => [
'usage' => $this->getMemoryUsage(),
'peak' => $this->getPeakMemoryUsage()
],
'cpu' => [
'usage' => $this->getCpuUsage(),
'last_15minutes' => $this->getCpuUsageLast15minutes(),
'cores' => $this->getCpuCores()
]
];
}
public function get(string $name): int|null|float
{
return match ($name) {
'memory' => $this->getMemoryUsage(),
'peak_memory' => $this->getPeakMemoryUsage(),
'cpu' => $this->getCpuUsage(),
'cpu_last_15minutes' => $this->getCpuUsageLast15minutes(),
'cpu_cores' => $this->getCpuCores(),
default => null
};
}
public function getMemoryUsage(): float
{
return memory_get_usage(true);
}
public function getPeakMemoryUsage(): float
{
return memory_get_peak_usage(true);
}
public function getCpuUsage(): float
{
return $this->getCpuLoad()[0];
}
public function getCpuUsageLast15minutes(): float
{
return $this->getCpuLoad()[1];
}
protected array $cpuLoad;
protected function getCpuLoad(): array
{
if (isset($this->cpuLoad)) {
$load = sys_getloadavg();
$cores = $this->getCpuCores();
array_walk($load, function (&$value) use ($cores) {
$value = $value / $cores;
});
$this->cpuLoad = $load;
unset($load);
}
return $this->cpuLoad;
}
protected function getCpuCores(): int
{
$cpu_cores = 1;
if (is_file('/proc/cpuinfo')) {
$cpuinfo = file('/proc/cpuinfo');
preg_match_all('/^processor/m', $cpuinfo, $matches);
$cpu_cores = count($matches[0]);
}
return $cpu_cores;
}
public function formatMemoryUsage(float $usage, string $unit = 'MB'): string
{
$sizeFactor = match ($unit) {
'MB' => 1024 * 1024,
'GB' => 1024 * 1024 * 1024,
default => 1
};
return number_format($usage / $sizeFactor, 2) . " {$unit}";
}
public function formatCpuLoad(float $load): string
{
return number_format($load * 100, 2) . '%';
}
}

0
cli/start_command Executable file → Normal file
View File

View File

@ -1,21 +0,0 @@
services:
mqtt:
profiles:
- mqtt
container_name: incoviba_mqtt
image: maateen/docker-beanstalkd
restart: unless-stopped
volumes:
- incoviba_mqtt:/var/lib/beanstalkd
mqtt-admin:
profiles:
- mqtt
container_name: incoviba_mqtt_admin
image: mitulislam/beanstalkd-aurora:latest
restart: unless-stopped
ports:
- "8093:3000"
volumes:
incoviba_mqtt: {}

View File

@ -18,8 +18,6 @@ services:
condition: service_healthy
test-redis:
condition: service_healthy
test-mqtt:
condition: service_started
test-db:
profiles:
@ -50,19 +48,6 @@ services:
networks:
- testing
test-mqtt:
profiles:
- testing
image: maateen/docker-beanstalkd
container_name: incoviba_test_mqtt
healthcheck:
test: [ "CMD", "nc", "-z", "localhost", "11300" ]
interval: 5s
timeout: 5s
retries: 5
networks:
- testing
volumes:
test-db: {}