Skip to content

Commit

Permalink
feat: Added duration filter (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrasseur-aneo authored Oct 10, 2023
2 parents 76b5360 + 6ec986e commit ca5b236
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Protos/V1/filters_common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

package armonik.api.grpc.v1;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "ArmoniK.Api.gRPC.V1";
Expand Down Expand Up @@ -71,3 +72,17 @@ message FilterBoolean {
bool value = 1;
FilterBooleanOperator operator = 2;
}

enum FilterDurationOperator {
FILTER_DURATION_OPERATOR_EQUAL = 0; /** Equal */
FILTER_DURATION_OPERATOR_NOT_EQUAL = 1; /** Not equal */
FILTER_DURATION_OPERATOR_SHORTER_THAN = 2; /** Shorter than */
FILTER_DURATION_OPERATOR_SHORTER_THAN_OR_EQUAL = 3; /** Shorter than or equal */
FILTER_DURATION_OPERATOR_LONGER_THAN_OR_EQUAL = 4; /** Longer than or equal */
FILTER_DURATION_OPERATOR_LONGER_THAN = 5; /** Longer than */
}

message FilterDuration {
google.protobuf.Duration value = 1;
FilterDurationOperator operator = 2;
}
1 change: 1 addition & 0 deletions Protos/V1/sessions_filters.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message FilterField {
FilterStatus filter_status = 5;
FilterDate filter_date = 6;
FilterArray filter_array = 7;
FilterDuration filter_duration = 8;
}
}

Expand Down
1 change: 1 addition & 0 deletions Protos/V1/tasks_filters.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message FilterField {
FilterStatus filter_status = 5;
FilterDate filter_date = 6;
FilterArray filter_array = 7;
FilterDuration filter_duration = 8;
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/python/src/armonik/client/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import cast, Tuple, List

from ..common import Task, Direction
from ..common.filter import StringFilter, StatusFilter, DateFilter, NumberFilter, Filter
from ..common.filter import StringFilter, StatusFilter, DateFilter, NumberFilter, Filter, DurationFilter
from ..protogen.client.tasks_service_pb2_grpc import TasksStub
from ..protogen.common.tasks_common_pb2 import GetTaskRequest, GetTaskResponse, ListTasksRequest, ListTasksDetailedResponse
from ..protogen.common.tasks_filters_pb2 import Filters as rawFilters, FiltersAnd as rawFilterAnd, FilterField as rawFilterField, FilterStatus as rawFilterStatus
Expand All @@ -25,12 +25,15 @@ class TaskFieldFilter:
SUBMITTED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_SUBMITTED_AT)), rawFilters, rawFilterAnd, rawFilterField)
STARTED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_STARTED_AT)), rawFilters, rawFilterAnd, rawFilterField)
ENDED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_ENDED_AT)), rawFilters, rawFilterAnd, rawFilterField)
CREATION_TO_END_DURATION = DurationFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_CREATION_TO_END_DURATION)), rawFilters, rawFilterAnd, rawFilterField)
PROCESSING_TO_END_DURATION = DurationFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_PROCESSING_TO_END_DURATION)), rawFilters, rawFilterAnd, rawFilterField)
POD_TTL = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_POD_TTL)), rawFilters, rawFilterAnd, rawFilterField)
POD_HOSTNAME = StringFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_POD_HOSTNAME)), rawFilters, rawFilterAnd, rawFilterField)
RECEIVED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_RECEIVED_AT)), rawFilters, rawFilterAnd, rawFilterField)
ACQUIRED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_ACQUIRED_AT)), rawFilters, rawFilterAnd, rawFilterField)
ERROR = StringFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_ERROR)), rawFilters, rawFilterAnd, rawFilterField)

MAX_DURATION = DurationFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_MAX_DURATION)), rawFilters, rawFilterAnd, rawFilterField)
MAX_RETRIES = NumberFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_MAX_RETRIES)), rawFilters, rawFilterAnd, rawFilterField)
PRIORITY = NumberFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_PRIORITY)), rawFilters, rawFilterAnd, rawFilterField)
PARTITION_ID = StringFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_PARTITION_ID)), rawFilters, rawFilterAnd, rawFilterField)
Expand Down
28 changes: 26 additions & 2 deletions packages/python/src/armonik/common/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Any, Type, Optional, Dict
from google.protobuf.message import Message
import google.protobuf.timestamp_pb2 as timestamp
import google.protobuf.duration_pb2 as duration
from ..protogen.common.filters_common_pb2 import *
import json

Expand Down Expand Up @@ -265,7 +266,9 @@ def to_basic_message(self) -> Message:


class DateFilter(Filter):
"""Filter for timestamp comparison"""
"""
Filter for timestamp comparison
"""
eq_ = FILTER_DATE_OPERATOR_EQUAL
ne_ = FILTER_DATE_OPERATOR_NOT_EQUAL
lt_ = FILTER_DATE_OPERATOR_BEFORE
Expand All @@ -282,7 +285,9 @@ def to_basic_message(self) -> Message:


class NumberFilter(Filter):
"""Filter for int comparison"""
"""
Filter for int comparison
"""
eq_ = FILTER_NUMBER_OPERATOR_EQUAL
ne_ = FILTER_NUMBER_OPERATOR_NOT_EQUAL
lt_ = FILTER_NUMBER_OPERATOR_LESS_THAN
Expand Down Expand Up @@ -331,3 +336,22 @@ def __init__(self, field: Optional[Message], disjunction_message_type: Type[Mess

def to_basic_message(self) -> Message:
return self.message_type(field=self.field, filter_array=self.inner_message_type(value=self.value, operator=self.operator))


class DurationFilter(Filter):
"""
Filter for duration comparison
"""
eq_ = FILTER_DURATION_OPERATOR_EQUAL
ne_ = FILTER_DURATION_OPERATOR_NOT_EQUAL
lt_ = FILTER_DURATION_OPERATOR_SHORTER_THAN
le_ = FILTER_DURATION_OPERATOR_SHORTER_THAN_OR_EQUAL
gt_ = FILTER_DURATION_OPERATOR_LONGER_THAN
ge_ = FILTER_DURATION_OPERATOR_LONGER_THAN_OR_EQUAL
value_type_ = duration.Duration

def __init__(self, field: Optional[Message], disjunction_message_type: Type[Message], conjunction_message_type: Type[Message], message_type: Type[Message], inner_message_type: Optional[Type[Message]] = FilterDuration, filters: Optional[List[List["Filter"]]] = None, value=None, operator=None):
super().__init__(field, disjunction_message_type, conjunction_message_type, message_type, inner_message_type, filters, value, operator)

def to_basic_message(self) -> Message:
return self.message_type(field=self.field, filter_duration=self.inner_message_type(value=self.value, operator=self.operator))

0 comments on commit ca5b236

Please sign in to comment.