Skip to content

Commit

Permalink
Manager test
Browse files Browse the repository at this point in the history
  • Loading branch information
maiphuong-van committed Sep 4, 2020
1 parent baaba4b commit 22e82c1
Show file tree
Hide file tree
Showing 2 changed files with 349 additions and 26 deletions.
24 changes: 13 additions & 11 deletions lib/crawly_ui/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ defmodule CrawlyUI.Manager do
end

@doc """
Returns the list of jobs.
Returns the list of jobs. For config, see [Scrivener documentation](https://hexdocs.pm/scrivener_list/readme.html#installation)
## Examples
iex> list_jobs()
[%Job{}, ...]
iex> list_jobs(%{page_number: 1, page_size: 10})
%Scrivener.Page{entries: [%Job{}, ...]}
"""
def list_jobs(params) do
Expand Down Expand Up @@ -192,11 +192,13 @@ defmodule CrawlyUI.Manager do
end_time = Timex.shift(start_time, minutes: -1)

Enum.each(jobs, fn job ->
cnt = Repo.one(
from i in "items",
where: i.job_id == ^job.id and i.inserted_at > ^end_time and i.inserted_at < ^start_time,
select: count("*")
)
cnt =
Repo.one(
from i in "items",
where:
i.job_id == ^job.id and i.inserted_at > ^end_time and i.inserted_at < ^start_time,
select: count("*")
)

{:ok, _} = update_job(job, %{crawl_speed: cnt})
end)
Expand Down Expand Up @@ -231,11 +233,11 @@ defmodule CrawlyUI.Manager do
end

@doc """
Returns the list of items.
Returns the list of items for a specific job that match the search string (if provided).
## Examples
iex> list_items()
iex> list_items(1, %{"search" => "id:1"})
[%Item{}, ...]
"""
Expand All @@ -250,7 +252,7 @@ defmodule CrawlyUI.Manager do
case String.contains?(search, ":") do
true ->
[key, value] = String.split(search, ":")
value = "%#{String.strip(value)}%"
value = "%#{String.trim(value)}%"

Item
|> where([i], i.job_id == ^job_id)
Expand Down
Loading

0 comments on commit 22e82c1

Please sign in to comment.