Updated to the ui, and to the api, now marks items as read and applied
This commit is contained in:
parent
be500fde33
commit
78649d6b5e
1
.gitignore
vendored
1
.gitignore
vendored
@ -179,3 +179,4 @@ fabric.properties
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
go-jobscraper
|
40
Makefile
Normal file
40
Makefile
Normal file
@ -0,0 +1,40 @@
|
||||
PROJECT = go-jobscraper
|
||||
|
||||
VERSION=`git describe --tags`
|
||||
BUILD=`date +%FT%T%z`
|
||||
|
||||
|
||||
ECR_REPO = git.caliban.io/martin
|
||||
|
||||
APP_IMAGE = $(ECR_REPO)/$(PROJECT):$(VERSION)
|
||||
|
||||
NO_CACHE = true
|
||||
|
||||
LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}"
|
||||
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
#CC=/usr/local/musl/bin/musl-gcc go build --ldflags '-linkmode external -extldflags "-static"' server.go
|
||||
GCO_ENABLED=0 GOOS=linux go build ${LDFLAGS} -o ${PROJECT} server.go
|
||||
# go build ${LDFLAGS} -o ${PROJECT} server.go
|
||||
|
||||
# docker build ./docker/. -t $(APP_IMAGE) --build-arg VERSION=$(VERSION) --no-cache=$(NO_CACHE) --compress=true
|
||||
docker build --platform linux/amd64 --no-cache -force-rm --tag ${APP_IMAGE} --file ./docker/Dockerfile .
|
||||
|
||||
|
||||
#push docker image to registry
|
||||
.PHONY: push
|
||||
push: build
|
||||
docker push $(APP_IMAGE)
|
||||
|
||||
|
||||
#push docker image to registry
|
||||
.PHONY: run
|
||||
run: build
|
||||
docker run $(APP_IMAGE)
|
||||
|
||||
ver:
|
||||
@echo '$(VERSION)'
|
||||
#echo $ERSION
|
||||
.PHONY: ver
|
6
dist/build/bundle.css
vendored
6
dist/build/bundle.css
vendored
File diff suppressed because one or more lines are too long
8
dist/build/bundle.css.map
vendored
8
dist/build/bundle.css.map
vendored
File diff suppressed because one or more lines are too long
2
dist/build/bundle.js
vendored
2
dist/build/bundle.js
vendored
File diff suppressed because one or more lines are too long
28
docker/Dockerfile
Normal file
28
docker/Dockerfile
Normal file
@ -0,0 +1,28 @@
|
||||
FROM debian:12-slim
|
||||
# FROM alpine:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN mkdir -p /app/dist
|
||||
|
||||
COPY ./go-jobscraper /app/
|
||||
|
||||
|
||||
COPY ./dist /app/dist
|
||||
|
||||
RUN apt-get update && apt-get install -y ca-certificates
|
||||
|
||||
# Need the following to get a go app to run inside a docker container
|
||||
# as per: https://www.fairlyusefulcode.co.uk/post/go-alpine-linux/ -- DEAD!!!
|
||||
# RUN apk upgrade musl
|
||||
# RUN apk add gcompat
|
||||
|
||||
# RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
|
||||
# RUN ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
|
||||
|
||||
RUN chmod +x /app/go-jobscraper
|
||||
|
||||
EXPOSE 3600
|
||||
|
||||
CMD [ "/app/go-jobscraper"]
|
||||
|
@ -53,7 +53,7 @@ func Grab(url string) []RssItem {
|
||||
|
||||
log.Printf("Length %v\n", len(items))
|
||||
|
||||
items = acceptItems(items)
|
||||
acceptItems(items)
|
||||
|
||||
log.Printf("Length %v\n", len(items))
|
||||
|
||||
|
38
server.go
38
server.go
@ -89,7 +89,10 @@ func main() {
|
||||
|
||||
c := cron.New()
|
||||
|
||||
c.AddFunc("*/15 * * * *", func() { JobWorker(db) })
|
||||
c.AddFunc("CRON_TZ=Europe/London */15 7-21 * * 1-5", func() { JobWorker(db) })
|
||||
c.AddFunc("CRON_TZ=Europe/London */60 22-23 * * 1-5", func() { JobWorker(db) })
|
||||
c.AddFunc("CRON_TZ=Europe/London */90 0-6 * * 1-5", func() { JobWorker(db) })
|
||||
c.AddFunc("CRON_TZ=Europe/London */90 0-23 * * 6,0", func() { JobWorker(db) })
|
||||
|
||||
c.Start()
|
||||
|
||||
@ -126,6 +129,9 @@ func main() {
|
||||
app.Put("/jobs/:id", func(c *fiber.Ctx) error {
|
||||
return markJobAsReadById(c, db)
|
||||
})
|
||||
app.Put("/apply/:id", func(c *fiber.Ctx) error {
|
||||
return markJobAsAppliedById(c, db)
|
||||
})
|
||||
|
||||
log.Fatalln(app.Listen(fmt.Sprintf(":%v", port)))
|
||||
|
||||
@ -152,6 +158,7 @@ func JobWorker(db *pgxpool.Pool) {
|
||||
entries := grabber.Grab(url.Url)
|
||||
|
||||
InsertJobs(db, entries)
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
}
|
||||
|
||||
@ -226,7 +233,7 @@ func getJobs(c *fiber.Ctx, db *pgxpool.Pool) error {
|
||||
|
||||
var jobs []JobEntries
|
||||
|
||||
rows, err := db.Query(context.Background(), `SELECT jobs._id, jobs.title, jobs.site, jobs.company, jobs.timestamp, coalesce(applied.a, 0) as a, coalesce(read.d, 0) as d
|
||||
rows, err := db.Query(context.Background(), `SELECT jobs._id, jobs.title, jobs.site, jobs.company, jobs.postdate, jobs.timestamp, coalesce(applied.a, 0) as a, coalesce(read.d, 0) as d
|
||||
FROM jobs
|
||||
left join applied on applied.aid = jobs._id
|
||||
left join read on read.rid = jobs._id order by jobs._id desc`)
|
||||
@ -240,7 +247,7 @@ left join read on read.rid = jobs._id order by jobs._id desc`)
|
||||
|
||||
for rows.Next() {
|
||||
var job JobEntries
|
||||
if err := rows.Scan(&job.ID, &job.Title, &job.Site, &job.Company, &job.Timestamp, &job.Applied, &job.Read); err != nil {
|
||||
if err := rows.Scan(&job.ID, &job.Title, &job.Site, &job.Company, &job.Postdate, &job.Timestamp, &job.Applied, &job.Read); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -301,7 +308,7 @@ func markJobAsReadById(c *fiber.Ctx, db *pgxpool.Pool) error {
|
||||
t := time.Now()
|
||||
|
||||
if id != "" {
|
||||
log.Println("Marking entry %v as read", id)
|
||||
log.Printf("Marking entry %v as read", id)
|
||||
|
||||
r, err := db.Exec(context.Background(), `INSERT INTO public."read" ("_id", rid, d) VALUES(nextval('read__id_seq'::regclass), $1, $2);`, id, t.Unix())
|
||||
if err != nil {
|
||||
@ -315,3 +322,26 @@ func markJobAsReadById(c *fiber.Ctx, db *pgxpool.Pool) error {
|
||||
|
||||
return c.SendStatus(200)
|
||||
}
|
||||
|
||||
func markJobAsAppliedById(c *fiber.Ctx, db *pgxpool.Pool) error {
|
||||
log.Println("markJobAsAppliedById")
|
||||
id := c.Params("id")
|
||||
log.Printf("-- %+v\n", id)
|
||||
|
||||
t := time.Now()
|
||||
|
||||
if id != "" {
|
||||
log.Printf("Marking entry %v as applied", id)
|
||||
|
||||
r, err := db.Exec(context.Background(), `INSERT INTO public."applied" ("_id", aid, a) VALUES(nextval('read__id_seq'::regclass), $1, $2);`, id, t.Unix())
|
||||
if err != nil {
|
||||
log.Printf("An error occured while executing query: %v", err)
|
||||
}
|
||||
if r.RowsAffected() != 1 {
|
||||
return errors.New("No row affected...")
|
||||
}
|
||||
log.Println("***")
|
||||
}
|
||||
|
||||
return c.SendStatus(200)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user