feat(logging): add logging to settings automation_jobs_cubit
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import '../../../../core/logging/logger.dart';
|
||||||
import '../../data/models/automation_job_model.dart';
|
import '../../data/models/automation_job_model.dart';
|
||||||
import '../../data/apis/automation_jobs_api.dart';
|
import '../../data/apis/automation_jobs_api.dart';
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ class AutomationJobsState extends Equatable {
|
|||||||
|
|
||||||
class AutomationJobsCubit extends Cubit<AutomationJobsState> {
|
class AutomationJobsCubit extends Cubit<AutomationJobsState> {
|
||||||
final AutomationJobsApi _api;
|
final AutomationJobsApi _api;
|
||||||
|
final Logger _logger = getLogger('features.settings.automation_jobs');
|
||||||
|
|
||||||
AutomationJobsCubit(this._api) : super(AutomationJobsState());
|
AutomationJobsCubit(this._api) : super(AutomationJobsState());
|
||||||
|
|
||||||
@@ -50,7 +52,12 @@ class AutomationJobsCubit extends Cubit<AutomationJobsState> {
|
|||||||
try {
|
try {
|
||||||
final jobs = await _api.list();
|
final jobs = await _api.list();
|
||||||
emit(state.copyWith(jobs: jobs, isLoading: false));
|
emit(state.copyWith(jobs: jobs, isLoading: false));
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
|
_logger.error(
|
||||||
|
message: 'Failed to load automation jobs',
|
||||||
|
error: e,
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
);
|
||||||
emit(state.copyWith(isLoading: false, error: e.toString()));
|
emit(state.copyWith(isLoading: false, error: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,8 +65,15 @@ class AutomationJobsCubit extends Cubit<AutomationJobsState> {
|
|||||||
Future<void> deleteJob(String id) async {
|
Future<void> deleteJob(String id) async {
|
||||||
try {
|
try {
|
||||||
await _api.delete(id);
|
await _api.delete(id);
|
||||||
|
_logger.info(message: 'Automation job deleted', extra: {'job_id': id});
|
||||||
await loadJobs();
|
await loadJobs();
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
|
_logger.error(
|
||||||
|
message: 'Failed to delete automation job',
|
||||||
|
error: e,
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
extra: {'job_id': id},
|
||||||
|
);
|
||||||
emit(state.copyWith(error: e.toString()));
|
emit(state.copyWith(error: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +91,17 @@ class AutomationJobsCubit extends Cubit<AutomationJobsState> {
|
|||||||
.map((job) => job.id == id ? updated : job)
|
.map((job) => job.id == id ? updated : job)
|
||||||
.toList();
|
.toList();
|
||||||
emit(state.copyWith(jobs: nextJobs));
|
emit(state.copyWith(jobs: nextJobs));
|
||||||
} catch (e) {
|
_logger.info(
|
||||||
|
message: 'Automation job status updated',
|
||||||
|
extra: {'job_id': id, 'enabled': enabled},
|
||||||
|
);
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_logger.error(
|
||||||
|
message: 'Failed to update automation job status',
|
||||||
|
error: e,
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
extra: {'job_id': id, 'enabled': enabled},
|
||||||
|
);
|
||||||
emit(state.copyWith(error: e.toString()));
|
emit(state.copyWith(error: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user