Skip to content

Commit 7b3a63d

Browse files
author
Benaim Axelle
committed
update
1 parent 5d24280 commit 7b3a63d

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

lib/job_cleaner.ex

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@ defmodule Queuetopia.JobCleaner do
1515

1616
@impl true
1717
def init(opts) do
18-
cleanup_interval = Keyword.fetch!(opts, :cleanup_interval)
19-
job_retention = Keyword.get(opts, :job_retention)
20-
2118
Process.send(self(), :cleanup, [])
2219

2320
state = %{
2421
repo: Keyword.fetch!(opts, :repo),
2522
scope: Keyword.fetch!(opts, :scope),
26-
cleanup_interval: cleanup_interval,
27-
job_retention: job_retention
23+
cleanup_interval: Keyword.fetch!(opts, :cleanup_interval),
24+
job_retention: Keyword.get(opts, :job_retention)
2825
}
2926

30-
{:ok, state}
27+
git{:ok, state}
3128
end
3229

3330
@impl true

test/job_cleaner_test.exs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,27 @@ defmodule Queuetopia.JobCleanerTest do
2121
:ok
2222
end
2323

24-
test "removes completed jobs older than 7 days retention period" do
25-
scope = TestQueuetopia.scope()
24+
test "removes completed jobs older than 7 days retention period during periodic cleanup" do
25+
start_supervised!(TestQueuetopia)
2626

27-
eight_days_old_completed_job =
27+
:timer.sleep(100)
28+
29+
eight_days_old_job =
2830
insert!(:job,
29-
scope: scope,
31+
scope: TestQueuetopia.scope(),
3032
done_at: datetime_days_ago(8)
3133
)
3234

33-
six_days_old_completed_job =
35+
six_days_old_job =
3436
insert!(:job,
35-
scope: scope,
37+
scope: TestQueuetopia.scope(),
3638
done_at: datetime_days_ago(6)
3739
)
3840

39-
pending_job_without_done_at =
40-
insert!(:job,
41-
scope: scope,
42-
done_at: nil
43-
)
41+
:timer.sleep(60)
4442

45-
start_supervised!(TestQueuetopia)
46-
:timer.sleep(100)
47-
48-
assert is_nil(TestRepo.get(Job, eight_days_old_completed_job.id))
49-
assert TestRepo.get(Job, six_days_old_completed_job.id)
50-
assert TestRepo.get(Job, pending_job_without_done_at.id)
43+
assert is_nil(TestRepo.get(Job, eight_days_old_job.id))
44+
assert TestRepo.get(Job, six_days_old_job.id)
5145
end
5246

5347
test "only removes jobs from its own scope" do
@@ -90,4 +84,17 @@ defmodule Queuetopia.JobCleanerTest do
9084

9185
assert is_nil(TestRepo.get(Job, eight_days_old_completed_job.id))
9286
end
87+
88+
test "cleanup is disabled by default" do
89+
old_job = insert!(:job, scope: "default_scope", done_at: datetime_days_ago(30))
90+
recent_job = insert!(:job, scope: "default_scope", done_at: datetime_days_ago(1))
91+
92+
Application.put_env(:queuetopia, TestQueuetopia, [])
93+
start_supervised!(TestQueuetopia)
94+
95+
:timer.sleep(100)
96+
97+
assert TestRepo.get(Job, old_job.id)
98+
assert TestRepo.get(Job, recent_job.id)
99+
end
93100
end

0 commit comments

Comments
 (0)