Skip to content
Merged
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
6 changes: 4 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Description
Provide a short description of what your changes entail and what services are affected.
`Provide a short description of what changes are being made and what services are being affected. Please include a Jira card link if applicable.`

## How to test
Provide the steps needed to test and verify your changes.
`Provide the steps needed to test and verify your changes.`


15 changes: 15 additions & 0 deletions services/ads/python/ads.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ def weighted_image(weight):
def status():
if flask_request.method == 'GET':

if flask_request.headers['X-Throw-Error'] == 'true':

try:
advertisements = Advertisement.query.all()
result.status_code = 200 # attempt to set property of null object
return result

except:
app.logger.error("An error occurred while getting ad.")
err = jsonify({'error': 'Internal Server Error'})
err.status_code = 500
return err

else:

try:
advertisements = Advertisement.query.all()
app.logger.info(f"Total advertisements available: {len(advertisements)}")
Expand Down
60 changes: 41 additions & 19 deletions services/frontend/site/components/common/Ad/Ad.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
import * as React from 'react';
import { useState } from 'react'
import { codeStash } from 'code-stash'
import config from '../../../featureFlags.config.json'

export interface AdDataResults {
data: object | null
path: string
data: object | null
path: string
}
// Advertisement banner
function Ad() {
const [data, setData] = React.useState<AdDataResults | null>(null)
const [isLoading, setLoading] = React.useState(false)
const adsPath = `${process.env.NEXT_PUBLIC_ADS_ROUTE}:${process.env.NEXT_PUBLIC_ADS_PORT}`
const [codeFlag, setCodeFlag] = useState<boolean>(false)

function getRandomArbitrary(min: number, max:number) {

function getRandomArbitrary(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min);
}

function fetchAd() {
fetch(`${adsPath}/ads`)
.then((res) => res.json())
.then((data) => {
const index = getRandomArbitrary(0,data.length);
setData(data[index])
})
.catch(e => console.error(e.message))
.finally(() => {
setLoading(false)
})
function fetchAd(flag: boolean) {
const headers = {
'X-Throw-Error': `${flag}`,
};
fetch(`${adsPath}/ads`, { headers })
.then((res) => res.json())
.then((data) => {
const index = getRandomArbitrary(0, data.length);
setData(data[index])
})
.catch(e => console.error(e.message))
.finally(() => {
setLoading(false)
})
}

React.useEffect(() => {
setLoading(true)
fetchAd()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
setLoading(true)
// check for config file, then grab feature flags
if (config) {
codeStash('error-tracking', { file: config })
.then((r: boolean) => {
setCodeFlag(r)
})
.catch((e: Error) => console.log(e))
}

// Fetch ad with error
codeFlag && fetchAd(true)


// Fetch normal ad
!codeFlag && fetchAd(false)

}, [codeFlag])

if (isLoading) return (
<div className="flex flex-row justify-center h-10">
Expand All @@ -42,7 +64,7 @@ function Ad() {
<div className="flex flex-row justify-center h-10">
AD HERE
</div>
)
)

return (
<div className="flex flex-row justify-center py-4">
Expand Down
5 changes: 5 additions & 0 deletions services/frontend/site/featureFlags.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"id": "2",
"name": "dbm",
"active": false
},
{
"id": "3",
"name": "error-tracking",
"active": false
}
]