Skip to content

Commit

Permalink
Merge pull request #510 from neet/api-fixes
Browse files Browse the repository at this point in the history
Api fixes
  • Loading branch information
neet committed Nov 9, 2022
2 parents 1094822 + 22733d5 commit 40ed83b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { TYPES } from '../../types';

@injectable()
export class JobRepository implements IJobRepository {
// Can be computed by tasks.queuePath();
private readonly _resource: string;
private readonly _origin: string;
private readonly _tasks = new CloudTasksClient();

Expand All @@ -24,6 +26,7 @@ export class JobRepository implements IJobRepository {
private readonly _logger: ILogger,
) {
this._origin = config.entries.server.origin;
this._resource = config.entries.tasks.resources.resubscription;
}

async queue(job: RefreshJob): Promise<void> {
Expand All @@ -32,6 +35,7 @@ export class JobRepository implements IJobRepository {
const url = origin.toString();

await this._tasks.createTask({
parent: this._resource,
task: {
httpRequest: new google.cloud.tasks.v2.HttpRequest({
httpMethod: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export interface IAppConfigServer {
readonly origin: string;
}

export interface IAppConfigTasks {
readonly resources: {
/** パフォーマーを再講読するタスクのリソース名 */
readonly resubscription: string;
};
}

export interface IAppConfigLogger {
readonly type: 'console' | 'cloud-logging';
}
Expand All @@ -25,6 +32,7 @@ export interface IAppConfigEntries {
readonly storage: IAppConfigStorage;
readonly server: IAppConfigServer;
readonly logger: IAppConfigLogger;
readonly tasks: IAppConfigTasks;
}

export interface IAppConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export abstract class AppConfigBase implements IAppConfig {
type: entries.storage?.type ?? 'filesystem',
bucket: entries.storage?.bucket ?? 'ril',
},
tasks: {
resources: {
resubscription: entries.tasks?.resources?.resubscription ?? '',
},
},
youtube: {
dataApiKey: entries.youtube?.dataApiKey,
websubEnabled: entries.youtube?.websubEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export class AppConfigEnvironment extends AppConfigBase implements IAppConfig {
})(),
origin: env('ORIGIN'),
},
tasks: {
resources: {
resubscription: env('TASKS_RESUBSCRIPTION_RESOURCE'),
},
},
logger: {
type: env('LOGGER_TYPE'),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoggingWinston } from '@google-cloud/logging-winston';
import { config, createLogger, format } from 'winston';
import { config, createLogger } from 'winston';

import { ILogger } from '../../app/services/Logger';

Expand All @@ -8,6 +8,7 @@ const loggingWinston = new LoggingWinston();
export const loggerCloudLogging: ILogger = createLogger({
level: 'info',
levels: config.syslog.levels,
format: format.combine(format.metadata(), format.json()),
// 勝手にフォーマットしてくるので要らない
// format,
transports: [loggingWinston],
});

1 comment on commit 40ed83b

@vercel
Copy link

@vercel vercel bot commented on 40ed83b Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.