Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status from kv #285

Merged
merged 5 commits into from
Apr 6, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/branch-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ jobs:

The API has been **deployed** to the **development** environment 🚀

- Endpoint: `dev-api.tarkov.dev`
- Playground: [dev-api.tarkov.dev/___graphql](https://dev-api.tarkov.dev/graphql)
- Endpoint: `dev-api.tarkov.dev/graphql`
- Playground: [dev-api.tarkov.dev](https://dev-api.tarkov.dev)

> Pusher: @${{ github.actor }}, Action: `${{ github.event_name }}`, Workflow: `${{ github.workflow }}`;

Expand All @@ -92,7 +92,7 @@ jobs:

The API has been **deployed** to the **production** environment 🚀

- Endpoint: `api.tarkov.dev`
- Playground: [api.tarkov.dev/___graphql](https://api.tarkov.dev/graphql)
- Endpoint: `api.tarkov.dev/graphql`
- Playground: [api.tarkov.dev](https://api.tarkov.dev)

> Pusher: @${{ github.actor }}, Action: `${{ github.event_name }}`, Workflow: `${{ github.workflow }}`;
4 changes: 2 additions & 2 deletions datasources/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ArchivedPricesAPI from './archived-prices.mjs';
import ItemsAPI from './items.mjs';
import MapAPI from './maps.mjs';
import SchemaAPI from './schema.mjs';
import status from './status.mjs';
import StatusAPI from './status.mjs';
import TasksAPI from './tasks.mjs';
import TraderInventoryAPI from './trader-inventory.mjs';
import TradersAPI from './traders.mjs';
Expand All @@ -22,7 +22,7 @@ class DataSource {
this.item = new ItemsAPI(this);
this.map = new MapAPI(this);
this.schema = new SchemaAPI(this);
this.status = status;
this.status = new StatusAPI(this);
this.traderInventory = new TraderInventoryAPI(this);
this.trader = new TradersAPI(this);
this.task = new TasksAPI(this);
Expand Down
94 changes: 12 additions & 82 deletions datasources/status.mjs
Original file line number Diff line number Diff line change
@@ -1,87 +1,17 @@
const servicesURL = 'https://status.escapefromtarkov.com/api/services';
const statusMessagesURL = 'https://status.escapefromtarkov.com/api/message/list';
const globalStatusUrl = 'https://status.escapefromtarkov.com/api/global/status';
import WorkerKV from '../utils/worker-kv.mjs';

const statusMap = [
'OK',
'Updating',
'Unstable',
'Down',
];

async function handleRequest(url) {
const init = {
headers: {
'accept': 'application/json, text/plain, */*',
},
};
return fetch(url, init).then(response => {
return response.json().catch(error => {
console.error(`Error parsing ${url} json: ${error.message}`);
return false;
});
}).catch(error => {
console.error(`Error retrieving ${url} status: ${error.message}`);
return false;
});
};

export default async () => {
let services = [];
let messages = [];
let globalStatus = {
message: 'N/A',
status: 2,
};

try {
const [servicesResponse, messagesResponse, globalStatusResponse] = await Promise.allSettled([
handleRequest(servicesURL),
handleRequest(statusMessagesURL),
handleRequest(globalStatusUrl),
]);

if (servicesResponse && servicesResponse.status && servicesResponse.status === 'fulfilled' && servicesResponse.value) {
services = servicesResponse.value.map((serviceStatus) => {
return {
...serviceStatus,
statusCode: statusMap[serviceStatus.status],
};
});
}

if (messagesResponse && messagesResponse.status && messagesResponse.status === 'fulfilled' && messagesResponse.value) {
messages = messagesResponse.value.map((message) => {
return {
...message,
statusCode: statusMap[message.type],
};
});
}

if (globalStatusResponse && globalStatusResponse.status && globalStatusResponse.status === 'fulfilled' && globalStatusResponse.value) {
globalStatus = globalStatusResponse.value;
}
} catch (requestError) {
console.error('Error responding to status request', requestError);
class StatusAPI extends WorkerKV {
constructor(dataSource) {
super('status_data', dataSource);
}

// Check if the message is 'Access denied' - This is likely an EFT API issue so we suppress the message
var globalStatusMessage = globalStatus.message;
if (globalStatusMessage === 'Access denied' && globalStatus.status !== null && globalStatus.status !== undefined) {
globalStatusMessage = ''
async getStatus(context) {
await this.init(context);
if (!this.cache) {
return Promise.reject(new Error('Status cache is empty'));
}
return this.cache.ServerStatus;
}
}

const generalStatus = {
name: 'Global',
message: globalStatusMessage,
status: globalStatus.status,
statusCode: statusMap[globalStatus.status],
};

return {
generalStatus: generalStatus,
currentStatuses: [...services, generalStatus],
messages: messages,
};
};
export default StatusAPI;
4 changes: 2 additions & 2 deletions resolvers/statusResolver.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
Query: {
status(obj, args, context, info) {
return context.data.status();
return context.data.status.getStatus(context);
}
}
},
};
2 changes: 2 additions & 0 deletions schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Barter {
source: String! @deprecated(reason: "Use trader and level instead.")
sourceName: ItemSourceName! @deprecated(reason: "Use trader instead.")
requirements: [PriceRequirement]! @deprecated(reason: "Use level instead.")
buyLimit: Int
}

type BossSpawn {
Expand Down Expand Up @@ -1311,6 +1312,7 @@ type TraderOffer implements Vendor {
#traderLevel: TraderLevel!
minTraderLevel: Int
taskUnlock: Task
buyLimit: Int
}

union TraderReputationLevel = TraderReputationLevelFence
Expand Down
3 changes: 0 additions & 3 deletions script/ci/Tarkov.dev.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
" pm.expect(pm.response.json().data.ammo[0].item.gridImageLink).to.be.a(\"string\");\r",
" pm.expect(pm.response.json().data.ammo[0].item.gridImageLinkFallback).to.be.a(\"string\");\r",
" pm.expect(pm.response.json().data.ammo[0].item.types).to.be.a(\"array\");\r",
" pm.expect(pm.response.json().data.ammo[0].item.avg24hPrice).to.be.a(\"number\");\r",
" pm.expect(pm.response.json().data.ammo[0].item.link).to.be.a(\"string\");\r",
" pm.expect(pm.response.json().data.ammo[0].item.sellFor).to.be.a(\"array\");\r",
" pm.expect(pm.response.json().data.ammo[0].item.buyFor).to.be.a(\"array\");\r",
Expand Down Expand Up @@ -163,7 +162,6 @@
" pm.expect(pm.response.json().data.hideoutModules[0].itemRequirements[0].item.gridImageLink).to.be.a(\"string\");\r",
" pm.expect(pm.response.json().data.hideoutModules[0].itemRequirements[0].item.gridImageLinkFallback).to.be.a(\"string\");\r",
" pm.expect(pm.response.json().data.hideoutModules[0].itemRequirements[0].item.types).to.be.a(\"array\");\r",
" pm.expect(pm.response.json().data.hideoutModules[0].itemRequirements[0].item.avg24hPrice).to.be.a(\"number\");\r",
" pm.expect(pm.response.json().data.hideoutModules[0].itemRequirements[0].item.link).to.be.a(\"string\");\r",
" pm.expect(pm.response.json().data.hideoutModules[0].itemRequirements[0].item.sellFor).to.be.a(\"array\");\r",
" pm.expect(pm.response.json().data.hideoutModules[0].itemRequirements[0].item.buyFor).to.be.a(\"array\");\r",
Expand Down Expand Up @@ -627,7 +625,6 @@
" pm.expect(pm.response.json().data.itemsByName[0].height).to.be.a(\"number\");\r",
" pm.expect(pm.response.json().data.itemsByName[0].width).to.be.a(\"number\");\r",
" pm.expect(pm.response.json().data.itemsByName[0].basePrice).to.be.a(\"number\");\r",
" pm.expect(pm.response.json().data.itemsByName[0].avg24hPrice).to.be.a(\"number\");\r",
"});\r",
"\r",
"pm.test(\"correct item common link data\", function () {\r",
Expand Down
Loading