diff --git a/avni-server-api/src/main/java/org/avni/server/dao/AvniJobRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/AvniJobRepository.java index 90fe75259..c9bfddc59 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/AvniJobRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/AvniJobRepository.java @@ -78,7 +78,7 @@ public String getLastJobStatusForSubjectType(SubjectType subjectType) { " left join batch_job_execution bje on i.job_instance_id = bje.job_instance_id\n" + " left join batch_job_execution_params bjep on bje.job_execution_id = bjep.job_execution_id\n" + "where i.job_name = 'syncAttributesJob'\n" + - " and key_name = 'subjectTypeId'\n" + + " and bjep.parameter_name = 'subjectTypeId'\n" + " and long_val = :subjectTypeId\n" + " and start_time is not null\n" + "order by start_time desc\n" + diff --git a/avni-server-api/src/main/resources/database/usefulQueries.sql b/avni-server-api/src/main/resources/database/usefulQueries.sql index 43c3611d6..df814f313 100644 --- a/avni-server-api/src/main/resources/database/usefulQueries.sql +++ b/avni-server-api/src/main/resources/database/usefulQueries.sql @@ -564,69 +564,98 @@ where entity.audit_id = a.id -- Find out scheduled jobs in the system -select * from - (select bje.job_execution_id execution_id, - bje.status status, - bje.exit_code exit_code, - bji.job_name "Type of Job", - bje.create_time create_time, - bje.start_time start_time, - bje.end_time end_time, - string_agg(case when bjep.key_name = 'uuid' then bjep.string_val else '' end::text, '') uuid, - string_agg(case when bjep.key_name = 'fileName' then bjep.string_val else '' end::text, '') fileName, - sum(case when bjep.key_name = 'noOfLines' then bjep.long_val else 0 end) noOfLines, - string_agg(case when bjep.key_name = 's3Key' then bjep.string_val else '' end::text, '') s3Key, - sum(case when bjep.key_name = 'userId' then bjep.long_val else 0 end) userId, - string_agg(case when bjep.key_name = 'type' then bjep.string_val::text else '' end::text, '') job_type, - max(case when bjep.key_name = 'startDate' then bjep.date_val::timestamp else null::timestamp end::timestamp) startDate, - max(case when bjep.key_name = 'endDate' then bjep.date_val::timestamp else null::timestamp end::timestamp) endDate, - string_agg(case when bjep.key_name = 'subjectTypeUUID' then bjep.string_val::text else '' end::text, '') subjectTypeUUID, - string_agg(case when bjep.key_name = 'programUUID' then bjep.string_val::text else '' end::text, '') programUUID, - string_agg(case when bjep.key_name = 'encounterTypeUUID' then bjep.string_val::text else '' end::text, '') encounterTypeUUID, - string_agg(case when bjep.key_name = 'reportType' then bjep.string_val::text else '' end::text, '') reportType, - max(bse.read_count) read_count, - max(bse.write_count) write_count, - max(bse.write_skip_count) write_skip_count - from batch_job_execution bje - left outer join batch_job_execution_params bjep on bje.job_execution_id = bjep.job_execution_id - left outer join batch_step_execution bse on bje.job_execution_id = bse.job_execution_id - left join batch_job_instance bji on bji.job_instance_id = bje.job_instance_id - group by bje.job_execution_id, bje.status, bje.exit_code, bje.create_time, bje.start_time, bje.end_time, bji.job_name - order by bje.create_time desc) jobs; +select *from (select bje.job_execution_id execution_id, + bje.status status, + bje.exit_code exit_code, + bji.job_name "Type of Job", + bje.create_time create_time, + bje.start_time start_time, + bje.end_time end_time, + string_agg(case when bjep.parameter_name = 'uuid' then bjep.string_val else '' end::text, '') uuid, + string_agg(case when bjep.parameter_name = 'fileName' then bjep.string_val else '' end::text, + '') fileName, + sum(case when bjep.parameter_name = 'noOfLines' then bjep.long_val else 0 end) noOfLines, + string_agg(case when bjep.parameter_name = 's3Key' then bjep.string_val else '' end::text, + '') s3Key, + sum(case when bjep.parameter_name = 'userId' then bjep.long_val else 0 end) userId, + string_agg(case when bjep.parameter_name = 'type' then bjep.string_val::text else '' end::text, + '') job_type, + max(case + when bjep.parameter_name = 'startDate' then bjep.date_val::timestamp + else null::timestamp end::timestamp) startDate, + max(case + when bjep.parameter_name = 'endDate' then bjep.date_val::timestamp + else null::timestamp end::timestamp) endDate, + string_agg(case + when bjep.parameter_name = 'subjectTypeUUID' then bjep.string_val::text + else '' end::text, + '') subjectTypeUUID, + string_agg( + case when bjep.parameter_name = 'programUUID' then bjep.string_val::text else '' end::text, + '') programUUID, + string_agg(case + when bjep.parameter_name = 'encounterTypeUUID' then bjep.string_val::text + else '' end::text, + '') encounterTypeUUID, + string_agg( + case when bjep.parameter_name = 'reportType' then bjep.string_val::text else '' end::text, + '') reportType, + max(bse.read_count) read_count, + max(bse.write_count) write_count, + max(bse.write_skip_count) write_skip_count + from batch_job_execution bje + left outer join batch_job_execution_params bjep on bje.job_execution_id = bjep.job_execution_id + left outer join batch_step_execution bse on bje.job_execution_id = bse.job_execution_id + left join batch_job_instance bji on bji.job_instance_id = bje.job_instance_id + group by bje.job_execution_id, bje.status, bje.exit_code, bje.create_time, bje.start_time, bje.end_time, + bji.job_name + order by bje.create_time desc) jobs; -- Commands to show status of Started and Pending Background jobs that were triggered today: -select users.username, jobs.* from - (select bje.job_execution_id execution_id, - bje.status status, - bje.exit_code exit_code, - bji.job_name "Type of Job", - bje.create_time create_time, - bje.start_time start_time, - bje.end_time end_time, - string_agg(case when bjep.key_name = 'uuid' then bjep.string_val else '' end::text, '') uuid, - string_agg(case when bjep.key_name = 'fileName' then bjep.string_val else '' end::text, '') fileName, - sum(case when bjep.key_name = 'noOfLines' then bjep.long_val else 0 end) noOfLines, - string_agg(case when bjep.key_name = 's3Key' then bjep.string_val else '' end::text, '') s3Key, - sum(case when bjep.key_name = 'userId' then bjep.long_val else 0 end) userId, - string_agg(case when bjep.key_name = 'type' then bjep.string_val::text else '' end::text, '') job_type, - max(case when bjep.key_name = 'startDate' then bjep.date_val::timestamp else null::timestamp end::timestamp) startDate, - max(case when bjep.key_name = 'endDate' then bjep.date_val::timestamp else null::timestamp end::timestamp) endDate, - string_agg(case when bjep.key_name = 'subjectTypeUUID' then bjep.string_val::text else '' end::text, '') subjectTypeUUID, - string_agg(case when bjep.key_name = 'programUUID' then bjep.string_val::text else '' end::text, '') programUUID, - string_agg(case when bjep.key_name = 'encounterTypeUUID' then bjep.string_val::text else '' end::text, '') encounterTypeUUID, - string_agg(case when bjep.key_name = 'reportType' then bjep.string_val::text else '' end::text, '') reportType, - max(bse.read_count) read_count, - max(bse.write_count) write_count, - max(bse.write_skip_count) write_skip_count - from batch_job_execution bje - left outer join batch_job_execution_params bjep on bje.job_execution_id = bjep.job_execution_id - left outer join batch_step_execution bse on bje.job_execution_id = bse.job_execution_id - left join batch_job_instance bji on bji.job_instance_id = bje.job_instance_id - group by bje.job_execution_id, bje.status, bje.exit_code, bje.create_time, bje.start_time, bje.end_time, bji.job_name - order by bje.create_time desc) jobs - join users on users.id = jobs.userId +select users.username, jobs.* +from (select bje.job_execution_id execution_id, + bje.status status, + bje.exit_code exit_code, + bji.job_name "Type of Job", + bje.create_time create_time, + bje.start_time start_time, + bje.end_time end_time, + string_agg(case when bjep.parameter_name = 'uuid' then bjep.string_val else '' end::text, '') uuid, + string_agg(case when bjep.parameter_name = 'fileName' then bjep.string_val else '' end::text, + '') fileName, + sum(case when bjep.parameter_name = 'noOfLines' then bjep.long_val else 0 end) noOfLines, + string_agg(case when bjep.parameter_name = 's3Key' then bjep.string_val else '' end::text, '') s3Key, + sum(case when bjep.parameter_name = 'userId' then bjep.long_val else 0 end) userId, + string_agg(case when bjep.parameter_name = 'type' then bjep.string_val::text else '' end::text, + '') job_type, + max(case + when bjep.parameter_name = 'startDate' then bjep.date_val::timestamp + else null::timestamp end::timestamp) startDate, + max(case + when bjep.parameter_name = 'endDate' then bjep.date_val::timestamp + else null::timestamp end::timestamp) endDate, + string_agg(case when bjep.parameter_name = 'subjectTypeUUID' then bjep.string_val::text else '' end::text, + '') subjectTypeUUID, + string_agg(case when bjep.parameter_name = 'programUUID' then bjep.string_val::text else '' end::text, + '') programUUID, + string_agg( + case when bjep.parameter_name = 'encounterTypeUUID' then bjep.string_val::text else '' end::text, + '') encounterTypeUUID, + string_agg(case when bjep.parameter_name = 'reportType' then bjep.string_val::text else '' end::text, + '') reportType, + max(bse.read_count) read_count, + max(bse.write_count) write_count, + max(bse.write_skip_count) write_skip_count + from batch_job_execution bje + left outer join batch_job_execution_params bjep on bje.job_execution_id = bjep.job_execution_id + left outer join batch_step_execution bse on bje.job_execution_id = bse.job_execution_id + left join batch_job_instance bji on bji.job_instance_id = bje.job_instance_id + group by bje.job_execution_id, bje.status, bje.exit_code, bje.create_time, bje.start_time, bje.end_time, + bji.job_name + order by bje.create_time desc) jobs + join users on users.id = jobs.userId where status in ('STARTING', 'STARTED') and create_time >= now()::date + interval '1m'; @@ -635,7 +664,7 @@ where status in ('STARTING', 'STARTED') select * from batch_job_execution bje inner join batch_job_instance bji on bje.job_instance_id = bji.job_instance_id inner join batch_job_execution_params bjep on bje.job_execution_id = bjep.job_execution_id - and bjep.key_name = 'organisationUUID' + and bjep.parameter_name = 'organisationUUID' and string_val = (select uuid from organisation where name = '') where bji.job_name = 'importZipJob';