]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Orchestrator/Scrapy/Schedule.hs
docker: add Dockerfile, docker-compose for postgres
[gargantext.git] / src / Gargantext / API / Orchestrator / Scrapy / Schedule.hs
1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE TypeOperators #-}
5 module Gargantext.API.Orchestrator.Scrapy.Schedule where
6
7 import Control.Lens
8 import Data.Aeson
9 import qualified Data.HashMap.Strict as H
10 import Data.Text (Text)
11 import GHC.Generics
12 import Servant
13 import Servant.Job.Utils (jsonOptions)
14 import Servant.Client
15 import Web.FormUrlEncoded hiding (parseMaybe)
16
17 data Schedule = Schedule
18 { s_project :: !Text
19 , s_spider :: !Text
20 , s_setting :: ![Text]
21 , s_jobid :: !(Maybe Text)
22 , s_version :: !(Maybe Text)
23 , s_extra :: ![(Text,[Text])]
24 }
25 deriving (Generic)
26
27 data ScheduleResponse = ScheduleResponse
28 { r_status :: !Text
29 , r_jobid :: !Text
30 }
31 deriving (Generic)
32
33 instance FromJSON ScheduleResponse where
34 parseJSON = genericParseJSON (jsonOptions "r_")
35
36 instance ToForm Schedule where
37 toForm s =
38 Form . H.fromList $
39 [("project", [s_project s])
40 ,("spider", [s_spider s])
41 ,("setting", s_setting s)
42 ,("jobid", s_jobid s ^.. _Just)
43 ,("_version", s_version s ^.. _Just)
44 ] ++ s_extra s
45
46 type Scrapy =
47 "schedule.json" :> ReqBody '[FormUrlEncoded] Schedule
48 :> Post '[JSON] ScheduleResponse
49
50 scrapyAPI :: Proxy Scrapy
51 scrapyAPI = Proxy
52
53 scrapySchedule :: Schedule -> ClientM ScheduleResponse
54 scrapySchedule = client scrapyAPI