@things-factory/weather 9.0.25 → 9.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,89 +1,35 @@
1
1
  "use strict";
2
+ /**
3
+ * Weather Service Headless Pool
4
+ * Using the unified headless pool system from @things-factory/shell
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.getBrowserPool = getBrowserPool;
4
- const tslib_1 = require("tslib");
5
- const genericPool = tslib_1.__importStar(require("generic-pool"));
6
- const env_1 = require("@things-factory/env");
7
- // puppeteer 모듈 동적 로드 (에러 처리 포함)
8
- let puppeteer;
9
- try {
10
- puppeteer = require('puppeteer');
11
- }
12
- catch (err) {
13
- console.error('Puppeteer 로드 실패:', err);
14
- }
15
- // 브라우저 풀 인스턴스
16
- let browserPool;
8
+ const shell_1 = require("@things-factory/shell");
9
+ // Create the weather pool instance
10
+ const weatherPool = (0, shell_1.getOrCreateHeadlessPool)('weather', {
11
+ min: 1,
12
+ max: 5,
13
+ headless: 'new', // Keep 'new' for weather compatibility
14
+ args: [
15
+ ...shell_1.HEADLESS_POOL_ARGUMENT_SETS.basic,
16
+ ...shell_1.HEADLESS_POOL_ARGUMENT_SETS.keychain_safe,
17
+ ...shell_1.HEADLESS_POOL_ARGUMENT_SETS.security_enhanced
18
+ ],
19
+ acquireTimeoutMillis: 10000,
20
+ idleTimeoutMillis: 30000, // 30초 후 유휴 인스턴스 제거
21
+ testOnBorrow: true,
22
+ enableCleanup: true
23
+ });
17
24
  /**
18
25
  * 헤드리스 브라우저 풀 가져오기 (싱글톤 패턴)
19
26
  */
20
27
  function getBrowserPool() {
21
- if (!browserPool) {
22
- browserPool = genericPool.createPool({
23
- // 브라우저 인스턴스 생성
24
- create() {
25
- console.log('날씨 서비스용 headless 브라우저 인스턴스 생성');
26
- return initializeChromium();
27
- },
28
- // 브라우저 인스턴스 유효성 검사
29
- validate(browser) {
30
- return Promise.race([
31
- new Promise(res => setTimeout(() => res(false), 1500)),
32
- browser
33
- .version()
34
- .then(_ => true)
35
- .catch(_ => false)
36
- ]);
37
- },
38
- // 브라우저 인스턴스 파괴
39
- destroy(browser) {
40
- return browser.close();
41
- }
42
- }, {
43
- // 풀 설정
44
- min: 1, // 최소 인스턴스 수
45
- max: 5, // 최대 인스턴스 수
46
- testOnBorrow: true,
47
- acquireTimeoutMillis: 10000,
48
- idleTimeoutMillis: 30000 // 30초 후 유휴 인스턴스 제거
49
- });
50
- // 애플리케이션 종료 시 정리
51
- process.on('exit', async () => {
52
- if (browserPool) {
53
- await browserPool.drain();
54
- await browserPool.clear();
55
- }
56
- });
57
- }
58
- return browserPool;
59
- }
60
- /**
61
- * Chromium 초기화
62
- */
63
- async function initializeChromium() {
64
- // puppeteer가 없으면 오류
65
- if (!puppeteer) {
66
- throw new Error('Puppeteer is not available');
67
- }
68
- // 크로미움 경로 (환경설정에서 가져옴)
69
- const CHROMIUM_PATH = env_1.config.get('CHROMIUM_PATH');
70
- // 실행 설정
71
- const launchSettings = {
72
- args: ['--hide-scrollbars', '--mute-audio', '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
73
- headless: 'new' // 'new' = 최신 헤드리스 모드
28
+ return {
29
+ acquire: () => weatherPool.acquire(),
30
+ release: (resource) => weatherPool.release(resource),
31
+ drain: () => weatherPool.cleanup(),
32
+ clear: () => weatherPool.reset()
74
33
  };
75
- // 크로미움 경로가 설정되어 있으면 사용
76
- if (CHROMIUM_PATH) {
77
- launchSettings['executablePath'] = CHROMIUM_PATH;
78
- }
79
- try {
80
- // 브라우저 실행
81
- const browser = await puppeteer.launch(launchSettings);
82
- return browser;
83
- }
84
- catch (err) {
85
- console.error('크로미움 초기화 실패:', err);
86
- throw err;
87
- }
88
34
  }
89
35
  //# sourceMappingURL=headless-pool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"headless-pool.js","sourceRoot":"","sources":["../../server/services/headless-pool.ts"],"names":[],"mappings":";;AAiBA,wCA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AM,EAAE,KAAK,IAAI,EAAE;YAC5B,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,WAAW,CAAC,KAAK,EAAE,CAAA;gBACzB,MAAM,WAAW,CAAC,KAAK,EAAE,CAAA;YAC3B,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,kBAAkB;IAC/B,oBAAoB;IACpB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IAC/C,CAAC;IAED,uBAAuB;IACvB,MAAM,aAAa,GAAG,YAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IAEjD,QAAQ;IACR,MAAM,cAAc,GAAG;QACrB,IAAI,EAAE,CAAC,mBAAmB,EAAE,cAAc,EAAE,cAAc,EAAE,0BAA0B,EAAE,yBAAyB,CAAC;QAClH,QAAQ,EAAE,KAAK,CAAC,qBAAqB;KACtC,CAAA;IAED,uBAAuB;IACvB,IAAI,aAAa,EAAE,CAAC;QAClB,cAAc,CAAC,gBAAgB,CAAC,GAAG,aAAa,CAAA;IAClD,CAAC;IAED,IAAI,CAAC;QACH,UAAU;QACV,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;QACtD,OAAO,OAAO,CAAA;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;QAClC,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC","sourcesContent":["import * as genericPool from 'generic-pool'\nimport { config } from '@things-factory/env'\n\n// puppeteer 모듈 동적 로드 (에러 처리 포함)\nlet puppeteer\ntry {\n puppeteer = require('puppeteer')\n} catch (err) {\n console.error('Puppeteer 로드 실패:', err)\n}\n\n// 브라우저 풀 인스턴스\nlet browserPool\n\n/**\n * 헤드리스 브라우저 풀 가져오기 (싱글톤 패턴)\n */\nexport function getBrowserPool() {\n if (!browserPool) {\n browserPool = genericPool.createPool(\n {\n // 브라우저 인스턴스 생성\n create() {\n console.log('날씨 서비스용 headless 브라우저 인스턴스 생성')\n return initializeChromium()\n },\n\n // 브라우저 인스턴스 유효성 검사\n validate(browser) {\n return Promise.race([\n new Promise(res => setTimeout(() => res(false), 1500)),\n browser\n .version()\n .then(_ => true)\n .catch(_ => false)\n ])\n },\n\n // 브라우저 인스턴스 파괴\n destroy(browser) {\n return browser.close()\n }\n },\n {\n // 풀 설정\n min: 1, // 최소 인스턴스 수\n max: 5, // 최대 인스턴스 수\n testOnBorrow: true,\n acquireTimeoutMillis: 10000,\n idleTimeoutMillis: 30000 // 30초 후 유휴 인스턴스 제거\n }\n )\n\n // 애플리케이션 종료 시 정리\n process.on('exit', async () => {\n if (browserPool) {\n await browserPool.drain()\n await browserPool.clear()\n }\n })\n }\n\n return browserPool\n}\n\n/**\n * Chromium 초기화\n */\nasync function initializeChromium() {\n // puppeteer가 없으면 오류\n if (!puppeteer) {\n throw new Error('Puppeteer is not available')\n }\n\n // 크로미움 경로 (환경설정에서 가져옴)\n const CHROMIUM_PATH = config.get('CHROMIUM_PATH')\n\n // 실행 설정\n const launchSettings = {\n args: ['--hide-scrollbars', '--mute-audio', '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],\n headless: 'new' // 'new' = 최신 헤드리스 모드\n }\n\n // 크로미움 경로가 설정되어 있으면 사용\n if (CHROMIUM_PATH) {\n launchSettings['executablePath'] = CHROMIUM_PATH\n }\n\n try {\n // 브라우저 실행\n const browser = await puppeteer.launch(launchSettings)\n return browser\n } catch (err) {\n console.error('크로미움 초기화 실패:', err)\n throw err\n }\n}\n"]}
1
+ {"version":3,"file":"headless-pool.js","sourceRoot":"","sources":["../../server/services/headless-pool.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAuBH,wCAOC;AA5BD,iDAA6G;AAE7G,mCAAmC;AACnC,MAAM,WAAW,GAAG,IAAA,+BAAuB,EAAC,SAAS,EAAE;IACrD,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,KAAK,EAAE,uCAAuC;IACxD,IAAI,EAAE;QACJ,GAAG,mCAA2B,CAAC,KAAK;QACpC,GAAG,mCAA2B,CAAC,aAAa;QAC5C,GAAG,mCAA2B,CAAC,iBAAiB;KACjD;IACD,oBAAoB,EAAE,KAAK;IAC3B,iBAAiB,EAAE,KAAK,EAAE,mBAAmB;IAC7C,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,IAAI;CACpB,CAAC,CAAA;AAEF;;GAEG;AACH,SAAgB,cAAc;IAC5B,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE;QACpC,OAAO,EAAE,CAAC,QAAa,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC;QACzD,KAAK,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE;QAClC,KAAK,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE;KACjC,CAAA;AACH,CAAC","sourcesContent":["/**\n * Weather Service Headless Pool\n * Using the unified headless pool system from @things-factory/shell\n */\n\nimport { getOrCreateHeadlessPool, getAllPoolStats, HEADLESS_POOL_ARGUMENT_SETS } from '@things-factory/shell'\n\n// Create the weather pool instance\nconst weatherPool = getOrCreateHeadlessPool('weather', {\n min: 1,\n max: 5,\n headless: 'new', // Keep 'new' for weather compatibility\n args: [\n ...HEADLESS_POOL_ARGUMENT_SETS.basic,\n ...HEADLESS_POOL_ARGUMENT_SETS.keychain_safe,\n ...HEADLESS_POOL_ARGUMENT_SETS.security_enhanced\n ],\n acquireTimeoutMillis: 10000,\n idleTimeoutMillis: 30000, // 30초 후 유휴 인스턴스 제거\n testOnBorrow: true,\n enableCleanup: true\n})\n\n/**\n * 헤드리스 브라우저 풀 가져오기 (싱글톤 패턴)\n */\nexport function getBrowserPool() {\n return {\n acquire: () => weatherPool.acquire(),\n release: (resource: any) => weatherPool.release(resource),\n drain: () => weatherPool.cleanup(),\n clear: () => weatherPool.reset()\n }\n}"]}