Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit fb03552

Browse files
committed
take events from scheduler
1 parent 3636c37 commit fb03552

File tree

10 files changed

+85
-0
lines changed

10 files changed

+85
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ gem 'dry-validation'
2828

2929
gem 'graphql'
3030
gem 'sidekiq'
31+
gem 'graphql-client'
3132

3233
gem 'json-schema'
3334
gem 'pagy', '~> 3.6.0'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ GEM
130130
websocket-driver (>= 0.6, < 0.8)
131131
ffi (1.11.1)
132132
graphql (1.9.15)
133+
graphql-client (0.16.0)
134+
activesupport (>= 3.0)
135+
graphql (~> 1.8)
133136
haml (5.0.4)
134137
temple (>= 0.8.0)
135138
tilt
@@ -374,6 +377,7 @@ DEPENDENCIES
374377
dry-system-hanami!
375378
dry-validation
376379
graphql
380+
graphql-client
377381
haml
378382
hanami (~> 1.3)
379383
hanami-fabrication

apps/web/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
end
1313
end
1414
resources :outputs, only: [:index, :new, :create]
15+
resources :events, only: [:index]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Web
2+
module Controllers
3+
module Events
4+
class Index
5+
include Web::Action
6+
include Import[
7+
operation: 'operations.event.index'
8+
]
9+
10+
def call(_)
11+
@events = operation.call
12+
p @events
13+
end
14+
15+
end
16+
end
17+
end
18+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.container
2+
= @events

apps/web/views/events/index.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Web
2+
module Views
3+
module Events
4+
class Index
5+
include Web::View
6+
end
7+
end
8+
end
9+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Operations
2+
module Event
3+
class Index < Base
4+
GRAPHQL_CLIENT = System::Container['omniscrapper.graphql_client']
5+
6+
Query = GRAPHQL_CLIENT.parse <<-'GRAPHQL'
7+
query {
8+
events {
9+
id,
10+
name,
11+
frequencyPeriod,
12+
frequencyQuantity
13+
}
14+
}
15+
GRAPHQL
16+
17+
18+
def call
19+
GRAPHQL_CLIENT.query(Query)
20+
end
21+
end
22+
end
23+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
RSpec.describe Web::Controllers::Events::Index, type: :action do
2+
let(:action) { described_class.new }
3+
let(:params) { Hash[] }
4+
5+
it 'is successful' do
6+
response = action.call(params)
7+
expect(response[0]).to eq 200
8+
end
9+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
RSpec.describe Web::Views::Events::Index, type: :view do
2+
let(:exposures) { Hash[format: :html] }
3+
let(:template) { Hanami::View::Template.new('apps/web/templates/events/index.html.erb') }
4+
let(:view) { described_class.new(template, exposures) }
5+
let(:rendered) { view.render }
6+
7+
it 'exposes #format' do
8+
expect(view.format).to eq exposures.fetch(:format)
9+
end
10+
end

system/container.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'dry/system/container'
22
require 'dry/system/hanami'
3+
require 'graphql/client'
4+
require 'graphql/client/http'
35

46
module System
57
class Container < Dry::System::Container
@@ -16,5 +18,11 @@ class Container < Dry::System::Container
1618
register 'omniscrapper.root' do
1719
OmniScrapper
1820
end
21+
22+
register 'omniscrapper.graphql_client' do
23+
http = GraphQL::Client::HTTP.new(ENV['SCHEDULER_API'])
24+
schema = GraphQL::Client.load_schema(http)
25+
GraphQL::Client.new(schema: schema, execute: http)
26+
end
1927
end
2028
end

0 commit comments

Comments
 (0)