Skip to content

Commit

Permalink
Add some logging and change some imports
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso committed Jul 31, 2024
1 parent 6bf009b commit 7aa256d
Show file tree
Hide file tree
Showing 8 changed files with 4,843 additions and 14,028 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function main() {
log.info(`Processsed args: ${JSON.stringify(processedArgs, null, 4)}`)
if (processedArgs.api) {
await new ReloadingAPI(envPath, config, pair, processedArgs).start().then(() => {
log.info('Running API restart process...')
log.info('Reloading API started...')
})
} else {
process.exit(0)
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class ReloadingAPI {

private async _watchEnv() {
return fs.watchFile(this._envPath, async () => {
log.info('env file change detected')
if (!this._restarting) {
this._restarting = true
await this.stop()
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { CombinedApiPaths } from '@prosopo/types'
import type { CombinedApiPaths } from '@prosopo/types'
import { ProviderEnvironment } from '@prosopo/env'
import { Server } from 'node:net'
import type { Server } from 'node:net'
import { getDB, getSecret } from './process.env.js'
import { getPairAsync } from '@prosopo/contract'
import { i18nMiddleware } from '@prosopo/common'
Expand All @@ -25,7 +25,7 @@ import getConfig from './prosopo.config.js'
import rateLimit from 'express-rate-limit'

function startApi(env: ProviderEnvironment, admin = false): Server {
env.logger.info(`Starting Prosopo API`)
env.logger.info('Starting Prosopo API')
const apiApp = express()
const apiPort = env.config.server.port

Expand Down Expand Up @@ -55,9 +55,6 @@ export async function start(env?: ProviderEnvironment, admin?: boolean) {
if (!env) {
loadEnv()

// Fail to start api if db is not defined
getDB()

const secret = getSecret()
const config = getConfig(undefined, undefined, undefined, {
solved: { count: 2 },
Expand All @@ -67,6 +64,9 @@ export async function start(env?: ProviderEnvironment, admin?: boolean) {
const pair = await getPairAsync(config.networks[config.defaultNetwork], secret, '')
env = new ProviderEnvironment(config, pair)
}
// Fail to start api if db env var is not defined
getDB()

await env.isReady()

// Start the scheduled job
Expand Down
4 changes: 2 additions & 2 deletions packages/env/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export class Environment implements ProsopoEnvironment {
})
}
if (this.db && this.db.connection?.readyState !== 1) {
this.logger.warn(`Database connection is not ready, reconnecting...`)
this.logger.warn('Database connection is not ready, reconnecting...')
await this.db.connect()
this.logger.info(`Connected to db`)
this.logger.info('Connected to db')
}
} catch (err) {
throw new ProsopoEnvError('GENERAL.ENVIRONMENT_NOT_READY', { context: { error: err }, logger: this.logger })
Expand Down
18,830 changes: 4,822 additions & 14,008 deletions packages/procaptcha-bundle/stats.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/provider/src/tasks/powCaptcha/powTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { u8aToHex } from '@polkadot/util'
import { PoWCaptcha } from '@prosopo/types'
import { Database } from '@prosopo/types-database'
import type { PoWCaptcha } from '@prosopo/types'
import type { Database } from '@prosopo/types-database'
import { ProsopoEnvError } from '@prosopo/common'
import { stringToHex } from '@polkadot/util'
import { KeyringPair } from '@polkadot/keyring/types'
import type { KeyringPair } from '@polkadot/keyring/types'
import { checkRecentPowSolution, checkPowSignature, checkPowSolution } from './powTasksUtils.js'

export class PowCaptchaManager {
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/src/tasks/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Tasks {

constructor(env: ProviderEnvironment) {
this.config = env.config
this.db = env.db as Database
this.db = env.getDb()
this.captchaConfig = env.config.captchas
this.logger = getLogger(env.config.logLevel, 'Tasks')
if (!env.pair) {
Expand Down
14 changes: 7 additions & 7 deletions packages/types-env/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { ApiPromise } from '@polkadot/api/promise/Api'
import { AssetsResolver, EnvironmentTypes, NetworkNames } from '@prosopo/types'
import { Database } from '@prosopo/types-database'
import { Keyring } from '@polkadot/keyring'
import { KeyringPair } from '@polkadot/keyring/types'
import { Logger } from '@prosopo/common'
import { ProsopoBasicConfigOutput } from '@prosopo/types'
import type { AssetsResolver, EnvironmentTypes, NetworkNames } from '@prosopo/types'
import type { Database } from '@prosopo/types-database'
import type { Keyring } from '@polkadot/keyring'
import type { KeyringPair } from '@polkadot/keyring/types'
import type { Logger } from '@prosopo/common'
import type { ProsopoBasicConfigOutput } from '@prosopo/types'

export interface ProsopoEnvironment {
config: ProsopoBasicConfigOutput
Expand All @@ -30,6 +29,7 @@ export interface ProsopoEnvironment {
assetsResolver: AssetsResolver | undefined
keyring: Keyring
pair: KeyringPair | undefined
getDb(): Database
isReady(): Promise<void>
importDatabase(): Promise<void>
}

0 comments on commit 7aa256d

Please sign in to comment.