Skip to content

Commit

Permalink
Merge pull request #2920 from statisticsnorway/MIM-2039_rss_joblog_er…
Browse files Browse the repository at this point in the history
…ror_view

[MIM-2039] Mim 2039 rss joblog error view
  • Loading branch information
johnnadeluy authored Sep 27, 2024
2 parents 828a1a0 + 9cde12a commit 4550e77
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 151 deletions.
50 changes: 35 additions & 15 deletions src/main/resources/lib/ssb/cron/pushRss.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { HttpRequestParams, HttpResponse, request } from '/lib/http-client'
import { getRssItemsStatkal } from '/lib/ssb/rss/statkal'
import { encryptRssNews, encryptRssStatkal } from '/lib/cipher/cipherRss'

export function pushRssNews(): string {
import { getRssItemsStatkal } from '../../../lib/ssb/rss/statkal'
import { encryptRssNews, encryptRssStatkal } from '../../../lib/cipher/cipherRss'
import { Events } from '../../../lib/ssb/repo/query'

export function pushRssNews(): RssResult {
const newsServiceUrl: string = app.config?.['ssb.baseUrl']
? app.config['ssb.baseUrl'] + '/_/service/mimir/news'
: 'https://www.utv.ssb.no/_/service/mimir/news'
Expand All @@ -11,17 +13,17 @@ export function pushRssNews(): string {
const encryptedBody: string = encryptRssNews(rssNews.body)
return postRssNews(encryptedBody)
} else {
return rssNews.message
return { message: rssNews.message }
}
}

export function pushRssStatkal(): string {
export function pushRssStatkal(): RssResult {
const rssStatkal: string | null = getRssItemsStatkal()
if (rssStatkal !== null) {
const encryptedBody: string = encryptRssStatkal(rssStatkal)
return postRssStatkal(encryptedBody)
} else {
return 'Ingen publiseringer å pushe til rss/statkal'
return { message: 'Ingen publiseringer å pushe til rss/statkal' }
}
}

Expand All @@ -47,15 +49,16 @@ function getRssNews(url: string): RssItems {
}
} else {
status.message = 'Henting av nyheter XP feilet - ' + rssNewsResponse.status
status.status = Events.REQUEST_GOT_ERROR_RESPONSE
}
} catch (e) {
status.message = 'Henting av nyheter XP feilet - ' + e
status.status = Events.REQUEST_GOT_ERROR_RESPONSE
}

return status
}

function postRssNews(encryptedRss: string): string {
function postRssNews(encryptedRss: string): RssResult {
const rssNewsBaseUrl: string =
app.config && app.config['ssb.baseUrl']
? app.config['ssb.baseUrl'] + '/rss/populate/news'
Expand All @@ -72,16 +75,24 @@ function postRssNews(encryptedRss: string): string {
try {
const pushRssNewsResponse: HttpResponse = request(requestParams)
if (pushRssNewsResponse.status === 200) {
return 'Push av RSS nyheter OK'
return {
message: 'Push av RSS nyheter OK',
}
} else {
return 'Push av RSS nyheter feilet - ' + pushRssNewsResponse.status
return {
message: 'Push av RSS nyheter feilet - ' + pushRssNewsResponse.status,
status: Events.REQUEST_GOT_ERROR_RESPONSE,
}
}
} catch (e) {
return 'Push av nyheter feilet - ' + e
return {
message: 'Push av nyheter feilet - ' + e,
status: Events.REQUEST_GOT_ERROR_RESPONSE,
}
}
}

function postRssStatkal(encryptedRss: string): string {
function postRssStatkal(encryptedRss: string): RssResult {
const rssStatkalBaseUrl: string =
app.config && app.config['ssb.baseUrl']
? app.config['ssb.baseUrl'] + '/rss/populate/statkal'
Expand All @@ -98,16 +109,25 @@ function postRssStatkal(encryptedRss: string): string {
try {
const pushRssStatkalResponse: HttpResponse = request(requestParams)
if (pushRssStatkalResponse.status === 200) {
return 'Push av RSS statkal OK'
return { message: 'Push av RSS statkal OK' }
} else {
return `Push av RSS statkal til ${rssStatkalBaseUrl} feilet - ${pushRssStatkalResponse.status} `
return {
message: `Push av RSS statkal til ${rssStatkalBaseUrl} feilet - ${pushRssStatkalResponse.status}`,
status: Events.REQUEST_GOT_ERROR_RESPONSE,
}
}
} catch (e) {
return 'Push av RSS statkal feilet - ' + e
return { message: 'Push av RSS statkal feilet - ' + e, status: Events.REQUEST_GOT_ERROR_RESPONSE }
}
}

interface RssItems {
body: string | null
message: RssResult['message']
status?: RssResult['status']
}

export interface RssResult {
message: string
status?: string
}
2 changes: 2 additions & 0 deletions src/main/resources/lib/ssb/cron/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ export interface RSSFilterLogData {
otherDataType: Array<string>
inRSSOrNoKey: Array<string>
savedQueryStatistics: Array<string>
start?: Array<string>
skipped: Array<string>
end: Array<string>
statistics?: Array<string>
}

export interface DataSourceInfo {
Expand Down
Loading

0 comments on commit 4550e77

Please sign in to comment.