1
0
mirror of https://github.com/immich-app/immich.git synced 2025-07-15 07:14:42 +02:00

refactor(server): jobs (#2023)

* refactor: job to domain

* chore: regenerate open api

* chore: tests

* fix: missing breaks

* fix: get asset with missing exif data

---------

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Jason Rasmussen
2023-03-20 11:55:28 -04:00
committed by GitHub
parent db6b14361d
commit 386eef046d
68 changed files with 1355 additions and 907 deletions

View File

@ -13,50 +13,68 @@ part of openapi.api;
class AllJobStatusResponseDto {
/// Returns a new [AllJobStatusResponseDto] instance.
AllJobStatusResponseDto({
required this.thumbnailGeneration,
required this.metadataExtraction,
required this.videoConversion,
required this.machineLearning,
required this.storageTemplateMigration,
required this.thumbnailGenerationQueue,
required this.metadataExtractionQueue,
required this.videoConversionQueue,
required this.objectTaggingQueue,
required this.clipEncodingQueue,
required this.storageTemplateMigrationQueue,
required this.backgroundTaskQueue,
required this.searchQueue,
});
JobCounts thumbnailGeneration;
JobCountsDto thumbnailGenerationQueue;
JobCounts metadataExtraction;
JobCountsDto metadataExtractionQueue;
JobCounts videoConversion;
JobCountsDto videoConversionQueue;
JobCounts machineLearning;
JobCountsDto objectTaggingQueue;
JobCounts storageTemplateMigration;
JobCountsDto clipEncodingQueue;
JobCountsDto storageTemplateMigrationQueue;
JobCountsDto backgroundTaskQueue;
JobCountsDto searchQueue;
@override
bool operator ==(Object other) => identical(this, other) || other is AllJobStatusResponseDto &&
other.thumbnailGeneration == thumbnailGeneration &&
other.metadataExtraction == metadataExtraction &&
other.videoConversion == videoConversion &&
other.machineLearning == machineLearning &&
other.storageTemplateMigration == storageTemplateMigration;
other.thumbnailGenerationQueue == thumbnailGenerationQueue &&
other.metadataExtractionQueue == metadataExtractionQueue &&
other.videoConversionQueue == videoConversionQueue &&
other.objectTaggingQueue == objectTaggingQueue &&
other.clipEncodingQueue == clipEncodingQueue &&
other.storageTemplateMigrationQueue == storageTemplateMigrationQueue &&
other.backgroundTaskQueue == backgroundTaskQueue &&
other.searchQueue == searchQueue;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(thumbnailGeneration.hashCode) +
(metadataExtraction.hashCode) +
(videoConversion.hashCode) +
(machineLearning.hashCode) +
(storageTemplateMigration.hashCode);
(thumbnailGenerationQueue.hashCode) +
(metadataExtractionQueue.hashCode) +
(videoConversionQueue.hashCode) +
(objectTaggingQueue.hashCode) +
(clipEncodingQueue.hashCode) +
(storageTemplateMigrationQueue.hashCode) +
(backgroundTaskQueue.hashCode) +
(searchQueue.hashCode);
@override
String toString() => 'AllJobStatusResponseDto[thumbnailGeneration=$thumbnailGeneration, metadataExtraction=$metadataExtraction, videoConversion=$videoConversion, machineLearning=$machineLearning, storageTemplateMigration=$storageTemplateMigration]';
String toString() => 'AllJobStatusResponseDto[thumbnailGenerationQueue=$thumbnailGenerationQueue, metadataExtractionQueue=$metadataExtractionQueue, videoConversionQueue=$videoConversionQueue, objectTaggingQueue=$objectTaggingQueue, clipEncodingQueue=$clipEncodingQueue, storageTemplateMigrationQueue=$storageTemplateMigrationQueue, backgroundTaskQueue=$backgroundTaskQueue, searchQueue=$searchQueue]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'thumbnail-generation'] = this.thumbnailGeneration;
json[r'metadata-extraction'] = this.metadataExtraction;
json[r'video-conversion'] = this.videoConversion;
json[r'machine-learning'] = this.machineLearning;
json[r'storage-template-migration'] = this.storageTemplateMigration;
json[r'thumbnail-generation-queue'] = this.thumbnailGenerationQueue;
json[r'metadata-extraction-queue'] = this.metadataExtractionQueue;
json[r'video-conversion-queue'] = this.videoConversionQueue;
json[r'object-tagging-queue'] = this.objectTaggingQueue;
json[r'clip-encoding-queue'] = this.clipEncodingQueue;
json[r'storage-template-migration-queue'] = this.storageTemplateMigrationQueue;
json[r'background-task-queue'] = this.backgroundTaskQueue;
json[r'search-queue'] = this.searchQueue;
return json;
}
@ -79,11 +97,14 @@ class AllJobStatusResponseDto {
}());
return AllJobStatusResponseDto(
thumbnailGeneration: JobCounts.fromJson(json[r'thumbnail-generation'])!,
metadataExtraction: JobCounts.fromJson(json[r'metadata-extraction'])!,
videoConversion: JobCounts.fromJson(json[r'video-conversion'])!,
machineLearning: JobCounts.fromJson(json[r'machine-learning'])!,
storageTemplateMigration: JobCounts.fromJson(json[r'storage-template-migration'])!,
thumbnailGenerationQueue: JobCountsDto.fromJson(json[r'thumbnail-generation-queue'])!,
metadataExtractionQueue: JobCountsDto.fromJson(json[r'metadata-extraction-queue'])!,
videoConversionQueue: JobCountsDto.fromJson(json[r'video-conversion-queue'])!,
objectTaggingQueue: JobCountsDto.fromJson(json[r'object-tagging-queue'])!,
clipEncodingQueue: JobCountsDto.fromJson(json[r'clip-encoding-queue'])!,
storageTemplateMigrationQueue: JobCountsDto.fromJson(json[r'storage-template-migration-queue'])!,
backgroundTaskQueue: JobCountsDto.fromJson(json[r'background-task-queue'])!,
searchQueue: JobCountsDto.fromJson(json[r'search-queue'])!,
);
}
return null;
@ -133,11 +154,14 @@ class AllJobStatusResponseDto {
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'thumbnail-generation',
'metadata-extraction',
'video-conversion',
'machine-learning',
'storage-template-migration',
'thumbnail-generation-queue',
'metadata-extraction-queue',
'video-conversion-queue',
'object-tagging-queue',
'clip-encoding-queue',
'storage-template-migration-queue',
'background-task-queue',
'search-queue',
};
}

View File

@ -24,12 +24,14 @@ class JobCommand {
String toJson() => value;
static const start = JobCommand._(r'start');
static const stop = JobCommand._(r'stop');
static const pause = JobCommand._(r'pause');
static const empty = JobCommand._(r'empty');
/// List of all possible values in this [enum][JobCommand].
static const values = <JobCommand>[
start,
stop,
pause,
empty,
];
static JobCommand? fromJson(dynamic value) => JobCommandTypeTransformer().decode(value);
@ -69,7 +71,8 @@ class JobCommandTypeTransformer {
if (data != null) {
switch (data.toString()) {
case r'start': return JobCommand.start;
case r'stop': return JobCommand.stop;
case r'pause': return JobCommand.pause;
case r'empty': return JobCommand.empty;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');

View File

@ -14,31 +14,31 @@ class JobCommandDto {
/// Returns a new [JobCommandDto] instance.
JobCommandDto({
required this.command,
required this.includeAllAssets,
required this.force,
});
JobCommand command;
bool includeAllAssets;
bool force;
@override
bool operator ==(Object other) => identical(this, other) || other is JobCommandDto &&
other.command == command &&
other.includeAllAssets == includeAllAssets;
other.force == force;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(command.hashCode) +
(includeAllAssets.hashCode);
(force.hashCode);
@override
String toString() => 'JobCommandDto[command=$command, includeAllAssets=$includeAllAssets]';
String toString() => 'JobCommandDto[command=$command, force=$force]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'command'] = this.command;
json[r'includeAllAssets'] = this.includeAllAssets;
json[r'force'] = this.force;
return json;
}
@ -62,7 +62,7 @@ class JobCommandDto {
return JobCommandDto(
command: JobCommand.fromJson(json[r'command'])!,
includeAllAssets: mapValueOfType<bool>(json, r'includeAllAssets')!,
force: mapValueOfType<bool>(json, r'force')!,
);
}
return null;
@ -113,7 +113,7 @@ class JobCommandDto {
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'command',
'includeAllAssets',
'force',
};
}

View File

@ -10,9 +10,9 @@
part of openapi.api;
class JobCounts {
/// Returns a new [JobCounts] instance.
JobCounts({
class JobCountsDto {
/// Returns a new [JobCountsDto] instance.
JobCountsDto({
required this.active,
required this.completed,
required this.failed,
@ -31,7 +31,7 @@ class JobCounts {
int waiting;
@override
bool operator ==(Object other) => identical(this, other) || other is JobCounts &&
bool operator ==(Object other) => identical(this, other) || other is JobCountsDto &&
other.active == active &&
other.completed == completed &&
other.failed == failed &&
@ -48,7 +48,7 @@ class JobCounts {
(waiting.hashCode);
@override
String toString() => 'JobCounts[active=$active, completed=$completed, failed=$failed, delayed=$delayed, waiting=$waiting]';
String toString() => 'JobCountsDto[active=$active, completed=$completed, failed=$failed, delayed=$delayed, waiting=$waiting]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
@ -60,10 +60,10 @@ class JobCounts {
return json;
}
/// Returns a new [JobCounts] instance and imports its values from
/// Returns a new [JobCountsDto] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static JobCounts? fromJson(dynamic value) {
static JobCountsDto? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
@ -72,13 +72,13 @@ class JobCounts {
// Note 2: this code is stripped in release mode!
assert(() {
requiredKeys.forEach((key) {
assert(json.containsKey(key), 'Required key "JobCounts[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "JobCounts[$key]" has a null value in JSON.');
assert(json.containsKey(key), 'Required key "JobCountsDto[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "JobCountsDto[$key]" has a null value in JSON.');
});
return true;
}());
return JobCounts(
return JobCountsDto(
active: mapValueOfType<int>(json, r'active')!,
completed: mapValueOfType<int>(json, r'completed')!,
failed: mapValueOfType<int>(json, r'failed')!,
@ -89,11 +89,11 @@ class JobCounts {
return null;
}
static List<JobCounts>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <JobCounts>[];
static List<JobCountsDto>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <JobCountsDto>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = JobCounts.fromJson(row);
final value = JobCountsDto.fromJson(row);
if (value != null) {
result.add(value);
}
@ -102,12 +102,12 @@ class JobCounts {
return result.toList(growable: growable);
}
static Map<String, JobCounts> mapFromJson(dynamic json) {
final map = <String, JobCounts>{};
static Map<String, JobCountsDto> mapFromJson(dynamic json) {
final map = <String, JobCountsDto>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = JobCounts.fromJson(entry.value);
final value = JobCountsDto.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
@ -116,13 +116,13 @@ class JobCounts {
return map;
}
// maps a json object with a list of JobCounts-objects as value to a dart map
static Map<String, List<JobCounts>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<JobCounts>>{};
// maps a json object with a list of JobCountsDto-objects as value to a dart map
static Map<String, List<JobCountsDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<JobCountsDto>>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = JobCounts.listFromJson(entry.value, growable: growable,);
final value = JobCountsDto.listFromJson(entry.value, growable: growable,);
if (value != null) {
map[entry.key] = value;
}

View File

@ -1,94 +0,0 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class JobId {
/// Instantiate a new enum with the provided [value].
const JobId._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const thumbnailGeneration = JobId._(r'thumbnail-generation');
static const metadataExtraction = JobId._(r'metadata-extraction');
static const videoConversion = JobId._(r'video-conversion');
static const machineLearning = JobId._(r'machine-learning');
static const storageTemplateMigration = JobId._(r'storage-template-migration');
/// List of all possible values in this [enum][JobId].
static const values = <JobId>[
thumbnailGeneration,
metadataExtraction,
videoConversion,
machineLearning,
storageTemplateMigration,
];
static JobId? fromJson(dynamic value) => JobIdTypeTransformer().decode(value);
static List<JobId>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <JobId>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = JobId.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [JobId] to String,
/// and [decode] dynamic data back to [JobId].
class JobIdTypeTransformer {
factory JobIdTypeTransformer() => _instance ??= const JobIdTypeTransformer._();
const JobIdTypeTransformer._();
String encode(JobId data) => data.value;
/// Decodes a [dynamic value][data] to a JobId.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
JobId? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data.toString()) {
case r'thumbnail-generation': return JobId.thumbnailGeneration;
case r'metadata-extraction': return JobId.metadataExtraction;
case r'video-conversion': return JobId.videoConversion;
case r'machine-learning': return JobId.machineLearning;
case r'storage-template-migration': return JobId.storageTemplateMigration;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [JobIdTypeTransformer] instance.
static JobIdTypeTransformer? _instance;
}

103
mobile/openapi/lib/model/job_name.dart generated Normal file
View File

@ -0,0 +1,103 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class JobName {
/// Instantiate a new enum with the provided [value].
const JobName._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const thumbnailGenerationQueue = JobName._(r'thumbnail-generation-queue');
static const metadataExtractionQueue = JobName._(r'metadata-extraction-queue');
static const videoConversionQueue = JobName._(r'video-conversion-queue');
static const objectTaggingQueue = JobName._(r'object-tagging-queue');
static const clipEncodingQueue = JobName._(r'clip-encoding-queue');
static const backgroundTaskQueue = JobName._(r'background-task-queue');
static const storageTemplateMigrationQueue = JobName._(r'storage-template-migration-queue');
static const searchQueue = JobName._(r'search-queue');
/// List of all possible values in this [enum][JobName].
static const values = <JobName>[
thumbnailGenerationQueue,
metadataExtractionQueue,
videoConversionQueue,
objectTaggingQueue,
clipEncodingQueue,
backgroundTaskQueue,
storageTemplateMigrationQueue,
searchQueue,
];
static JobName? fromJson(dynamic value) => JobNameTypeTransformer().decode(value);
static List<JobName>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <JobName>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = JobName.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [JobName] to String,
/// and [decode] dynamic data back to [JobName].
class JobNameTypeTransformer {
factory JobNameTypeTransformer() => _instance ??= const JobNameTypeTransformer._();
const JobNameTypeTransformer._();
String encode(JobName data) => data.value;
/// Decodes a [dynamic value][data] to a JobName.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
JobName? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data.toString()) {
case r'thumbnail-generation-queue': return JobName.thumbnailGenerationQueue;
case r'metadata-extraction-queue': return JobName.metadataExtractionQueue;
case r'video-conversion-queue': return JobName.videoConversionQueue;
case r'object-tagging-queue': return JobName.objectTaggingQueue;
case r'clip-encoding-queue': return JobName.clipEncodingQueue;
case r'background-task-queue': return JobName.backgroundTaskQueue;
case r'storage-template-migration-queue': return JobName.storageTemplateMigrationQueue;
case r'search-queue': return JobName.searchQueue;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [JobNameTypeTransformer] instance.
static JobNameTypeTransformer? _instance;
}