Skip to content

Commit

Permalink
Merge pull request #1401 from OpenFn/1400-lost-query
Browse files Browse the repository at this point in the history
closes #1400
  • Loading branch information
taylordowns2000 authored Nov 18, 2023
2 parents 4badf0a + 8e1e602 commit 48f5bb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
14 changes: 6 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ bearing with us as we move towards our first stable Lightning release.)

### Fixed

- [#1140](https://github.com/OpenFn/Lightning/issues/1140) Adaptor icons load
gracefully
- [#1283](https://github.com/OpenFn/Lightning/issues/1283) Selected dataclip
gets lost when starting a manual workorder from the inspector interface
- Fixed janitor lost query calculation
[#1400](https://github.com/OpenFn/Lightning/issues/1400)
- Adaptor icons load gracefully
[#1140](https://github.com/OpenFn/Lightning/issues/1140)
- Selected dataclip gets lost when starting a manual workorder from the
inspector interface [#1283](https://github.com/OpenFn/Lightning/issues/1283)
- Ensure that the whole edge when selected is highlighted
[#1160](https://github.com/OpenFn/Lightning/issues/1160)
- Fix "Reconfigure Github" button in Project Settings
Expand All @@ -150,13 +152,10 @@ bearing with us as we move towards our first stable Lightning release.)

- Fix long name on workflow cards
[#1102](https://github.com/OpenFn/Lightning/issues/1102)

- Fix highlighted Edge can get out of sync with selected Edge
[#1099](https://github.com/OpenFn/Lightning/issues/1099)

- Creating a new user without a password fails and there is no user feedback
[#731](https://github.com/OpenFn/Lightning/issues/731)

- Crash when setting up version control
[#1112](https://github.com/OpenFn/Lightning/issues/1112)

Expand All @@ -182,7 +181,6 @@ bearing with us as we move towards our first stable Lightning release.)

- Modified audit trail to handle lots of different kind of audit events
[#271](https://github.com/OpenFn/Lightning/issues/271)/[#44](https://github.com/OpenFn/Lightning/issues/44)

- Fix randomly unresponsive job panel after job deletion
[#1113](https://github.com/OpenFn/Lightning/issues/1113)

Expand Down
9 changes: 7 additions & 2 deletions lib/lightning/attempts/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ defmodule Lightning.Attempts.Query do
"""
@spec lost(DateTime.t()) :: Ecto.Queryable.t()
def lost(%DateTime{} = now) do
max_run_duration = Application.get_env(:lightning, :max_run_duration)
grace_period = Lightning.Config.grace_period()
earliest_acceptable_start = DateTime.add(now, grace_period)

oldest_valid_claim =
now
|> DateTime.add(-max_run_duration, :millisecond)
|> DateTime.add(-grace_period, :millisecond)

final_states = Attempt.final_states()

from(att in Attempt,
where: is_nil(att.finished_at),
where: att.state not in ^final_states,
where: att.claimed_at < ^earliest_acceptable_start
where: att.claimed_at < ^oldest_valid_claim
)
end
end
18 changes: 14 additions & 4 deletions test/lightning/attempts/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ defmodule Lightning.Attempts.QueryTest do
)

now = DateTime.utc_now()
max_run_duration = Application.get_env(:lightning, :max_run_duration)
grace_period = Lightning.Config.grace_period()

earliest_acceptable_start = DateTime.add(now, grace_period)
assert grace_period == max_run_duration * 0.2

cutoff_age_in_seconds =
((grace_period + max_run_duration) / 1000) |> trunc()

attempt_to_be_marked_lost =
insert(:attempt,
work_order: work_order,
starting_trigger: trigger,
dataclip: dataclip,
state: :claimed,
claimed_at: DateTime.add(earliest_acceptable_start, -10)
claimed_at:
DateTime.add(now, -cutoff_age_in_seconds)
|> DateTime.add(-2)
)

_crashed_but_NOT_lost =
Expand All @@ -38,7 +44,9 @@ defmodule Lightning.Attempts.QueryTest do
starting_trigger: trigger,
dataclip: dataclip,
state: :crashed,
claimed_at: DateTime.add(earliest_acceptable_start, -10)
claimed_at:
DateTime.add(now, -cutoff_age_in_seconds)
|> DateTime.add(-2)
)

_another_attempt =
Expand All @@ -47,7 +55,9 @@ defmodule Lightning.Attempts.QueryTest do
starting_trigger: trigger,
dataclip: dataclip,
state: :claimed,
claimed_at: DateTime.add(earliest_acceptable_start, 10)
claimed_at:
DateTime.add(now, -cutoff_age_in_seconds)
|> DateTime.add(2)
)

lost_attempts =
Expand Down

0 comments on commit 48f5bb6

Please sign in to comment.