Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.development.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ DATABASE_URL="postgresql://username:password@localhost/omniscrapper_hq_developme
SERVE_STATIC_ASSETS="true"
WEB_SESSIONS_SECRET="00bdb001d8f18ee8e8e4b7d063877243348fa8cb2c3879a52052c33871f09228"
API_SESSIONS_SECRET="985f2d9f9d1f729e3204d011354792a148e548f599b3554b2bedc591949240d0"
SCHEDULER_API=http://localhost:2301/api/graphql
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ gem 'dry-validation'

gem 'graphql'
gem 'sidekiq'
gem 'graphql-client'

gem 'json-schema'
gem 'pagy', '~> 3.6.0'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ GEM
websocket-driver (>= 0.6, < 0.8)
ffi (1.11.1)
graphql (1.9.15)
graphql-client (0.16.0)
activesupport (>= 3.0)
graphql (~> 1.8)
haml (5.0.4)
temple (>= 0.8.0)
tilt
Expand Down Expand Up @@ -374,6 +377,7 @@ DEPENDENCIES
dry-system-hanami!
dry-validation
graphql
graphql-client
haml
hanami (~> 1.3)
hanami-fabrication
Expand Down
1 change: 1 addition & 0 deletions apps/web/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
end
end
resources :outputs, only: [:index, :new, :create]
resources :schedules, only: [:index]
18 changes: 18 additions & 0 deletions apps/web/controllers/schedules/index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Web
module Controllers
module Schedules
class Index
include Web::Action
include Import[
operation: 'operations.schedule.index'
]

expose :schedules

def call(_)
@schedules = operation.call
end
end
end
end
end
17 changes: 17 additions & 0 deletions apps/web/templates/schedules/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%table.table.table-bordered.table-hover.table-sm
%thead
%tr
%th Name
%th Task
%th Frequency
%th
%tbody
- schedules.each do |event|
%tr
%td= schedule.name
%td= schedule.task_id
%td= schedule.frequency
%td
= edit_button("#")
= remove_button("#")

2 changes: 2 additions & 0 deletions apps/web/templates/shared/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
= link_to 'Outputs', routes.outputs_path, class: 'nav-link'
%li.nav-item
= link_to 'Tasks', routes.tasks_path, class: 'nav-link'
%li.nav-item
= link_to 'Schedules', routes.schedules_path, class: 'nav-link'
%li.nav-item
= link_to 'Results', routes.test_results_path, class: 'nav-link'
%li.nav-item
Expand Down
9 changes: 9 additions & 0 deletions apps/web/views/schedules/index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Web
module Views
module Schedules
class Index
include Web::View
end
end
end
end
15 changes: 15 additions & 0 deletions lib/omniscrapper_hq/entities/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Event
attr_reader :id, :name, :task_id, :frequency_period, :frequency_quantity

def initialize(id:, name:, task_id:, frequency_period:, frequency_quantity:)
@id = id
@name = name
@task_id = task_id
@frequency_period = frequency_period
@frequency_quantity = frequency_quantity
end

def frequency
"#{frequency_quantity} #{frequency_period}"
end
end
32 changes: 32 additions & 0 deletions lib/omniscrapper_hq/operations/schedule/index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Operations
module Schedule
class Index < Base
GRAPHQL_CLIENT ||= System::Container['omniscrapper.graphql_client']

Query ||= GRAPHQL_CLIENT.parse <<-'GRAPHQL'
query {
events {
id,
name,
taskId,
frequencyPeriod,
frequencyQuantity
}
}
GRAPHQL

def call
results = GRAPHQL_CLIENT.query(Query)
results.data.events.map do |event|
::Event.new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be called Schedule, not Event.
We keep the period when task is performed.

id: event.id,
name: event.name,
task_id: event.task_id,
frequency_quantity: event.frequency_quantity,
frequency_period: event.frequency_period
)
end
end
end
end
end
9 changes: 9 additions & 0 deletions spec/web/controllers/events/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RSpec.describe Web::Controllers::Events::Index, type: :action do
let(:action) { described_class.new }
let(:params) { Hash[] }

it 'is successful' do
response = action.call(params)
expect(response[0]).to eq 200
end
end
10 changes: 10 additions & 0 deletions spec/web/views/events/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RSpec.describe Web::Views::Events::Index, type: :view do
let(:exposures) { Hash[format: :html] }
let(:template) { Hanami::View::Template.new('apps/web/templates/events/index.html.erb') }
let(:view) { described_class.new(template, exposures) }
let(:rendered) { view.render }

it 'exposes #format' do
expect(view.format).to eq exposures.fetch(:format)
end
end
8 changes: 8 additions & 0 deletions system/container.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'dry/system/container'
require 'dry/system/hanami'
require 'graphql/client'
require 'graphql/client/http'

module System
class Container < Dry::System::Container
Expand All @@ -16,5 +18,11 @@ class Container < Dry::System::Container
register 'omniscrapper.root' do
OmniScrapper
end

register 'omniscrapper.graphql_client' do
http = GraphQL::Client::HTTP.new(ENV['SCHEDULER_API'])
schema = GraphQL::Client.load_schema(http)
GraphQL::Client.new(schema: schema, execute: http)
end
end
end