mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-05 23:47:54 +08:00
add job status check for ghosting reminder
This commit is contained in:
@@ -375,3 +375,16 @@ export async function saveJobHireStatusRecord(
|
|||||||
await jobHireStatusRecordRepository.save(record);
|
await jobHireStatusRecordRepository.save(record);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getJobHireStatusRecord(
|
||||||
|
ds: DataSource,
|
||||||
|
encryptJobId: string
|
||||||
|
) {
|
||||||
|
const repo = ds.getRepository(JobHireStatusRecord)
|
||||||
|
const result = await repo.findOne({
|
||||||
|
where: {
|
||||||
|
encryptJobId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -34,7 +34,10 @@ export async function launchBoss(browser: Browser) {
|
|||||||
}
|
}
|
||||||
await setDomainLocalStorage(browser, localStoragePageUrl, bossLocalStorage)
|
await setDomainLocalStorage(browser, localStoragePageUrl, bossLocalStorage)
|
||||||
try {
|
try {
|
||||||
await Promise.all([page.goto(bossChatUiUrl, { timeout: 0 }), page.waitForNavigation()])
|
await Promise.all([
|
||||||
|
page.goto(bossChatUiUrl, { timeout: 0 }),
|
||||||
|
page.waitForNavigation({ timeout: 120 * 1000 })
|
||||||
|
])
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error?.message?.startsWith('net::ERR_INTERNET_DISCONNECTED')) {
|
if (error?.message?.startsWith('net::ERR_INTERNET_DISCONNECTED')) {
|
||||||
throw new Error('ERR_INTERNET_DISCONNECTED')
|
throw new Error('ERR_INTERNET_DISCONNECTED')
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { MsgStatus, type ChatListItem } from './types'
|
|||||||
import { Browser, Page } from 'puppeteer'
|
import { Browser, Page } from 'puppeteer'
|
||||||
import { sendGptContent, sendLookForwardReplyEmotion } from './boss-operation'
|
import { sendGptContent, sendLookForwardReplyEmotion } from './boss-operation'
|
||||||
import { sleep, sleepWithRandomDelay } from '@geekgeekrun/utils/sleep.mjs'
|
import { sleep, sleepWithRandomDelay } from '@geekgeekrun/utils/sleep.mjs'
|
||||||
|
import { waitForPage } from '@geekgeekrun/utils/puppeteer/wait.mjs'
|
||||||
import attachListenerForKillSelfOnParentExited from '../../utils/attachListenerForKillSelfOnParentExited'
|
import attachListenerForKillSelfOnParentExited from '../../utils/attachListenerForKillSelfOnParentExited'
|
||||||
import { app, dialog } from 'electron'
|
import { app, dialog } from 'electron'
|
||||||
import { initDb } from '@geekgeekrun/sqlite-plugin'
|
import { initDb } from '@geekgeekrun/sqlite-plugin'
|
||||||
@@ -11,7 +12,11 @@ import {
|
|||||||
readConfigFile
|
readConfigFile
|
||||||
} from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
} from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||||
import { ChatMessageRecord } from '@geekgeekrun/sqlite-plugin/dist/entity/ChatMessageRecord'
|
import { ChatMessageRecord } from '@geekgeekrun/sqlite-plugin/dist/entity/ChatMessageRecord'
|
||||||
import { saveChatMessageRecord } from '@geekgeekrun/sqlite-plugin/dist/handlers'
|
import {
|
||||||
|
saveChatMessageRecord,
|
||||||
|
getJobHireStatusRecord,
|
||||||
|
saveJobHireStatusRecord
|
||||||
|
} from '@geekgeekrun/sqlite-plugin/dist/handlers'
|
||||||
import { writeStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
import { writeStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import { pipeWriteRegardlessError } from '../utils/pipe'
|
import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||||
@@ -19,6 +24,9 @@ import { BossInfo } from '@geekgeekrun/sqlite-plugin/dist/entity/BossInfo'
|
|||||||
import { messageForSaveFilter } from '../../../common/utils/chat-list'
|
import { messageForSaveFilter } from '../../../common/utils/chat-list'
|
||||||
import { RECHAT_CONTENT_SOURCE, RECHAT_LLM_FALLBACK } from '../../../common/enums/auto-start-chat'
|
import { RECHAT_CONTENT_SOURCE, RECHAT_LLM_FALLBACK } from '../../../common/enums/auto-start-chat'
|
||||||
import gtag from '../../utils/gtag'
|
import gtag from '../../utils/gtag'
|
||||||
|
import { JobHireStatus } from '@geekgeekrun/sqlite-plugin/dist/enums';
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
import cheerio from 'cheerio'
|
||||||
|
|
||||||
const throttleIntervalMinutes =
|
const throttleIntervalMinutes =
|
||||||
readConfigFile('boss.json').autoReminder?.throttleIntervalMinutes ?? 10
|
readConfigFile('boss.json').autoReminder?.throttleIntervalMinutes ?? 10
|
||||||
@@ -104,6 +112,88 @@ async function saveCurrentChatRecord(page) {
|
|||||||
await saveChatMessageRecord(ds, chatRecordList)
|
await saveChatMessageRecord(ds, chatRecordList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkJobIsClosed() {
|
||||||
|
const encryptJobId = await pageMapByName.boss!.evaluate(() => {
|
||||||
|
return document.querySelector('.chat-conversation .chat-im.chat-editor')?.__vue__?.conversation$.encryptJobId
|
||||||
|
})
|
||||||
|
if (!encryptJobId) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let isJobClosed = false
|
||||||
|
let record = await getJobHireStatusRecord(await dbInitPromise, encryptJobId)
|
||||||
|
// not seen before, or last seen more than 6 hours ago
|
||||||
|
// fetch new status
|
||||||
|
if (
|
||||||
|
!record ||
|
||||||
|
(record.hireStatus === JobHireStatus.HIRING &&
|
||||||
|
Date.now() - Number(dayjs(record.lastSeenDate)) > 6 * 60 * 60 * 1000)
|
||||||
|
) {
|
||||||
|
const positionNameElHandle = await pageMapByName.boss!.$(
|
||||||
|
`#main .chat-conversation [ka="geek_chat_job_detail"] .right-content`
|
||||||
|
)
|
||||||
|
if (!positionNameElHandle) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
positionNameElHandle.click()
|
||||||
|
try {
|
||||||
|
const targetPage = await waitForPage(pageMapByName.boss!.browser(), async (page) => {
|
||||||
|
const url = page.url()
|
||||||
|
if (
|
||||||
|
url.startsWith(`https://www.zhipin.com/job_detail/${encryptJobId}`) &&
|
||||||
|
(await page.evaluate(() => document.readyState === 'complete'))
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
const htmlContent = await targetPage.content()
|
||||||
|
if (htmlContent) {
|
||||||
|
const $ = cheerio.load(htmlContent)
|
||||||
|
const [jobBannerEl] = $('#main .job-banner') ?? []
|
||||||
|
if (!jobBannerEl) {
|
||||||
|
console.log(`access might be blocked`)
|
||||||
|
if (
|
||||||
|
htmlContent.includes(`您访问的页面不存在`) ||
|
||||||
|
location.href === `https://www.zhipin.com/`
|
||||||
|
) {
|
||||||
|
await saveJobHireStatusRecord(await dbInitPromise, {
|
||||||
|
encryptJobId,
|
||||||
|
hireStatus: JobHireStatus.DELETED,
|
||||||
|
lastSeenDate: new Date()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const [jobStatusTextEl] = $('#main .job-banner .job-status') ?? []
|
||||||
|
if (jobStatusTextEl) {
|
||||||
|
const jobStatusText = $(jobStatusTextEl).text()?.trim() ?? ''
|
||||||
|
if ([`职位已关闭`].includes(jobStatusText)) {
|
||||||
|
await saveJobHireStatusRecord(await dbInitPromise, {
|
||||||
|
encryptJobId,
|
||||||
|
hireStatus: JobHireStatus.CLOSED,
|
||||||
|
lastSeenDate: new Date()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await saveJobHireStatusRecord(await dbInitPromise, {
|
||||||
|
encryptJobId,
|
||||||
|
hireStatus: JobHireStatus.HIRING,
|
||||||
|
lastSeenDate: new Date()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
targetPage.close().catch(() => void 0)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`checkJobIsClosed error: ${err}`)
|
||||||
|
}
|
||||||
|
record = await getJobHireStatusRecord(await dbInitPromise, encryptJobId)
|
||||||
|
}
|
||||||
|
if (record.hireStatus !== JobHireStatus.HIRING) {
|
||||||
|
isJobClosed = true
|
||||||
|
}
|
||||||
|
return isJobClosed
|
||||||
|
}
|
||||||
|
|
||||||
let browser: null | Browser = null
|
let browser: null | Browser = null
|
||||||
const mainLoop = async () => {
|
const mainLoop = async () => {
|
||||||
if (browser) {
|
if (browser) {
|
||||||
@@ -303,7 +393,9 @@ const mainLoop = async () => {
|
|||||||
)?.filter(messageForSaveFilter) ?? []
|
)?.filter(messageForSaveFilter) ?? []
|
||||||
|
|
||||||
const lastGeekMessageSendTime = historyMessageList.findLast((it) => it.isSelf)?.time ?? 0
|
const lastGeekMessageSendTime = historyMessageList.findLast((it) => it.isSelf)?.time ?? 0
|
||||||
|
const isJobClosed = await checkJobIsClosed()
|
||||||
if (
|
if (
|
||||||
|
!isJobClosed &&
|
||||||
isExpectJobTypeMatch &&
|
isExpectJobTypeMatch &&
|
||||||
historyMessageList[historyMessageList.length - 1].isSelf &&
|
historyMessageList[historyMessageList.length - 1].isSelf &&
|
||||||
historyMessageList[historyMessageList.length - 1].status === MsgStatus.HAS_READ &&
|
historyMessageList[historyMessageList.length - 1].status === MsgStatus.HAS_READ &&
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
export async function waitForPage(browser, predicate, {
|
||||||
|
polling = 1000, timeout = 10 * 1000
|
||||||
|
} = {}) {
|
||||||
|
let intervalTimer = null
|
||||||
|
let timeoutTimer = null
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
timeoutTimer = setTimeout(
|
||||||
|
() => {
|
||||||
|
clearInterval(intervalTimer)
|
||||||
|
clearInterval(timeoutTimer)
|
||||||
|
reject(
|
||||||
|
new Error(`waitForPage timeout after ${timeout} ms`)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
timeout
|
||||||
|
)
|
||||||
|
intervalTimer = setInterval(async () => {
|
||||||
|
const allPages = await browser.pages()
|
||||||
|
let target = null
|
||||||
|
for (let i = allPages.length - 1; i >= 0; i--) {
|
||||||
|
const currentPage = allPages[i]
|
||||||
|
if (
|
||||||
|
await predicate(currentPage)
|
||||||
|
) {
|
||||||
|
clearInterval(intervalTimer)
|
||||||
|
clearInterval(timeoutTimer)
|
||||||
|
resolve(currentPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, polling)
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user