From fea8380ea54b2a700dcf6e6685a4fb2a0392f671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kutryj?= Date: Fri, 9 Jan 2026 12:03:42 +0100 Subject: [PATCH 1/2] feat(zebra): bypass job execution time limit restriction for verified orgs Verified organizations now bypass the max_job_execution_time_limit feature flag when it would restrict them below the standard 24-hour maximum. If the feature flag extends the limit beyond 24 hours, verified orgs still benefit from the extended limit. --- .../zebra/apis/internal_task_api/schedule.ex | 6 ++++-- zebra/test/support/stubbed_provider.ex | 4 ++++ .../apis/internal_task_api/schedule_test.exs | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/zebra/lib/zebra/apis/internal_task_api/schedule.ex b/zebra/lib/zebra/apis/internal_task_api/schedule.ex index e0ac981e9..5f4cdb9be 100644 --- a/zebra/lib/zebra/apis/internal_task_api/schedule.ex +++ b/zebra/lib/zebra/apis/internal_task_api/schedule.ex @@ -138,10 +138,12 @@ defmodule Zebra.Apis.InternalTaskApi.Schedule do end defp find_max_and_default_job_time_limits(org_id) do - if org_verified?(org_id) do + {max_limit, default_limit} = find_feature_based_job_time_limits(org_id) + + if org_verified?(org_id) and max_limit < @max_job_execution_time_limit do {@max_job_execution_time_limit, @default_job_execution_time_limit} else - find_feature_based_job_time_limits(org_id) + {max_limit, default_limit} end end diff --git a/zebra/test/support/stubbed_provider.ex b/zebra/test/support/stubbed_provider.ex index 839f85820..e4de1f908 100644 --- a/zebra/test/support/stubbed_provider.ex +++ b/zebra/test/support/stubbed_provider.ex @@ -36,6 +36,10 @@ defmodule Support.StubbedProvider do feature("max_job_execution_time_limit", [:enabled, {:quantity, 48 * 60}]) end + defp max_job_time_limit_feature("enabled_48h_verified") do + feature("max_job_execution_time_limit", [:enabled, {:quantity, 48 * 60}]) + end + defp max_job_time_limit_feature(_org_id) do feature("max_job_execution_time_limit", [:hidden]) end diff --git a/zebra/test/zebra/apis/internal_task_api/schedule_test.exs b/zebra/test/zebra/apis/internal_task_api/schedule_test.exs index 4301d3ed4..2927977e4 100644 --- a/zebra/test/zebra/apis/internal_task_api/schedule_test.exs +++ b/zebra/test/zebra/apis/internal_task_api/schedule_test.exs @@ -266,6 +266,27 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do # requested limit of 180 minutes should be capped to 30 minutes by feature flag assert 30 * 60 == Schedule.configure_execution_time_limit(org_id, 180) end + + test "when org is verified and feature extends limit beyond 24h => uses extended limit" do + org_id = "enabled_48h_verified" + + Cachex.clear(:zebra_cache) + + GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ -> + InternalApi.Organization.DescribeResponse.new( + status: + InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)), + organization: + InternalApi.Organization.Organization.new( + org_username: "verified-org", + verified: true + ) + ) + end) + + # verified org with 48h feature flag should be able to use the extended limit + assert 30 * 60 * 60 == Schedule.configure_execution_time_limit(org_id, 30 * 60) + end end # From c06f4524a1d1037737dddc04d246026d3718cdd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kutryj?= Date: Fri, 9 Jan 2026 12:16:29 +0100 Subject: [PATCH 2/2] toil(zebra): fix specs, improve id naming --- zebra/test/support/stubbed_provider.ex | 14 +++-- .../apis/internal_task_api/schedule_test.exs | 56 ++++++++++++++++--- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/zebra/test/support/stubbed_provider.ex b/zebra/test/support/stubbed_provider.ex index e4de1f908..89acd426b 100644 --- a/zebra/test/support/stubbed_provider.ex +++ b/zebra/test/support/stubbed_provider.ex @@ -20,23 +20,27 @@ defmodule Support.StubbedProvider do def e1_to_f1_org_id, do: @e1_to_f1_org_id def e2_to_f1_org_id, do: @e2_to_f1_org_id - defp max_job_time_limit_feature("enabled_30") do + defp max_job_time_limit_feature("org_30min_limit_valid_request") do feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}]) end - defp max_job_time_limit_feature("enabled_30_verified") do + defp max_job_time_limit_feature("org_30min_limit_invalid_request") do feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}]) end - defp max_job_time_limit_feature("enabled_30_unverified") do + defp max_job_time_limit_feature("org_30min_limit_verified") do feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}]) end - defp max_job_time_limit_feature("enabled_48h") do + defp max_job_time_limit_feature("org_30min_limit_unverified") do + feature("max_job_execution_time_limit", [:enabled, {:quantity, 30}]) + end + + defp max_job_time_limit_feature("org_48h_limit_invalid_request") do feature("max_job_execution_time_limit", [:enabled, {:quantity, 48 * 60}]) end - defp max_job_time_limit_feature("enabled_48h_verified") do + defp max_job_time_limit_feature("org_48h_limit_verified") do feature("max_job_execution_time_limit", [:enabled, {:quantity, 48 * 60}]) end diff --git a/zebra/test/zebra/apis/internal_task_api/schedule_test.exs b/zebra/test/zebra/apis/internal_task_api/schedule_test.exs index 2927977e4..3407d7e45 100644 --- a/zebra/test/zebra/apis/internal_task_api/schedule_test.exs +++ b/zebra/test/zebra/apis/internal_task_api/schedule_test.exs @@ -167,14 +167,42 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do end test "when feature is enabled and limit from request is valid => returns limit from request in seconds" do - org_id = "enabled_30" + org_id = "org_30min_limit_valid_request" + + Cachex.clear(:zebra_cache) + + GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ -> + InternalApi.Organization.DescribeResponse.new( + status: + InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)), + organization: + InternalApi.Organization.Organization.new( + org_username: "unverified-org", + verified: false + ) + ) + end) # requested limit is less then feature limit of 30 minutes assert 15 * 60 == Schedule.configure_execution_time_limit(org_id, 15) end test "when feature is enabled, limit from request is invalid, and feature limit >= default limit => returns default limit" do - org_id = "enabled_48h" + org_id = "org_48h_limit_invalid_request" + + Cachex.clear(:zebra_cache) + + GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ -> + InternalApi.Organization.DescribeResponse.new( + status: + InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)), + organization: + InternalApi.Organization.Organization.new( + org_username: "unverified-org", + verified: false + ) + ) + end) # if requested limit <= 0 and feature limit >= max limit -> configure it to default one assert @default_job_execution_time_limit == @@ -189,7 +217,21 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do end test "when feature is enabled, limit from request is invalid, and feature limit < default limit => returns feature limit" do - org_id = "enabled_30" + org_id = "org_30min_limit_invalid_request" + + Cachex.clear(:zebra_cache) + + GrpcMock.stub(Support.FakeServers.OrganizationApi, :describe, fn _, _ -> + InternalApi.Organization.DescribeResponse.new( + status: + InternalApi.ResponseStatus.new(code: InternalApi.ResponseStatus.Code.value(:OK)), + organization: + InternalApi.Organization.Organization.new( + org_username: "unverified-org", + verified: false + ) + ) + end) # if requested limit <= 0 and feature limit < max limit -> configure it to feature limit assert 30 * 60 == Schedule.configure_execution_time_limit(org_id, 0) @@ -200,7 +242,7 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do end test "when org is verified and feature is enabled => bypasses feature limit and uses requested limit" do - org_id = "enabled_30_verified" + org_id = "org_30min_limit_verified" Cachex.clear(:zebra_cache) @@ -222,7 +264,7 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do end test "when org is verified and feature is enabled with invalid request => returns default limit" do - org_id = "enabled_30_verified" + org_id = "org_30min_limit_verified" Cachex.clear(:zebra_cache) @@ -247,7 +289,7 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do end test "when org is not verified and feature is enabled => applies feature limit" do - org_id = "enabled_30_unverified" + org_id = "org_30min_limit_unverified" Cachex.clear(:zebra_cache) @@ -268,7 +310,7 @@ defmodule Zebra.Apis.InternalTaskApi.ScheduleTest do end test "when org is verified and feature extends limit beyond 24h => uses extended limit" do - org_id = "enabled_48h_verified" + org_id = "org_48h_limit_verified" Cachex.clear(:zebra_cache)