From 8ccdbab4c25ad52ef8c832cd0a03ca0d52f6a04e Mon Sep 17 00:00:00 2001 From: Bishwajyoti Roy Date: Tue, 12 Mar 2024 01:09:24 +0530 Subject: [PATCH] Cleanup and actions update --- .github/workflows/deploy.yaml | 18 ++++++++++++++++++ src/index.ts | 13 +++++++------ src/selenium/clock-in.ts | 6 ++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index df4cd92..0416e93 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -42,3 +42,21 @@ jobs: - name: Build service run: yarn build + + - name: Deploy Changes + run: | + mkdir ~/.ssh + touch ~/.ssh/known_hosts + + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/private_key + chmod 600 ~/.ssh/private_key + ls -al ~/.ssh/ + ssh-keygen -R ${{ secrets.SSH_HOST }} + sudo chown -v $USER ~/.ssh/known_hosts + + # ssh-keygen -H -t rsa ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts + scp -i ~/.ssh/private_key -r ./dist ${{ secrets.USER_NAME }}@${{ secrets.SSH_HOST }}:/home/ec2-user/auto-presence + ssh -o StrictHostKeyChecking=no -i ~/.ssh/private_key ${{ secrets.USER_NAME }}@${{ secrets.SSH_HOST}} ' + + ls + ' diff --git a/src/index.ts b/src/index.ts index 4ebc99c..076b11b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import "./server"; import { WebDriver } from "selenium-webdriver"; initUserTable(); +const ONE_HOUR_MS = 3600000; const clockIn = async (delayMs) => { let driver: WebDriver; @@ -20,7 +21,7 @@ const clockIn = async (delayMs) => { driver = await loadKeka(); await handleClockIn(driver); - const successMessage = `✅ Clocked in 🕘 Successfully at: ${DateTime.now().toLocaleString( + const successMessage = `✅ Clock-In 🕘 Successful at: ${DateTime.now().toLocaleString( DateTime.DATETIME_MED )}`; await sendNotification({ @@ -31,7 +32,6 @@ const clockIn = async (delayMs) => { console.log(successMessage); console.log("===================================="); } catch (error) { - driver.close(); const errorMessage = `❌ Clock-In 🕘 failed at: ${DateTime.now().toLocaleString( DateTime.DATETIME_MED )}`; @@ -44,6 +44,7 @@ const clockIn = async (delayMs) => { console.log(errorMessage); console.log(error); console.log("===================================="); + driver?.close(); } }; @@ -65,7 +66,6 @@ const clockOut = async (delayMs) => { console.log(successMessage); console.log("===================================="); } catch (error) { - driver.close(); const errorMessage = `❌ Clock-Out 🕕 failed at: ${DateTime.now().toLocaleString( DateTime.DATETIME_MED )}`; @@ -78,12 +78,13 @@ const clockOut = async (delayMs) => { console.log(errorMessage); console.log(error); console.log("===================================="); + driver?.close(); } }; const run = async () => { cron.schedule("30 09 * * 1-5", () => { - const delayMs = Math.floor(Math.random() * 1200000); + const delayMs = Math.floor(Math.random() * ONE_HOUR_MS); const message = `🕘 Clock-in started at: ${DateTime.now().toLocaleString( DateTime.DATETIME_MED )}`; @@ -97,8 +98,8 @@ const run = async () => { console.log("===================================="); clockIn(0); }); - cron.schedule("14 21 * * 1-5", () => { - const delayMs = Math.floor(Math.random() * 1200000); + cron.schedule("30 19 * * 1-5", () => { + const delayMs = Math.floor(Math.random() * ONE_HOUR_MS); const message = `🕕 Clock-out started at: ${DateTime.now().toLocaleString( DateTime.DATETIME_MED )}`; diff --git a/src/selenium/clock-in.ts b/src/selenium/clock-in.ts index bdf95ce..765b151 100644 --- a/src/selenium/clock-in.ts +++ b/src/selenium/clock-in.ts @@ -1,4 +1,5 @@ import { By, WebDriver, until } from "selenium-webdriver"; +import { asyncDelay } from "../utils/delay"; export const handleClockIn = async (driver: WebDriver) => { await driver.get("https://expian.keka.com/#/me/attendance/logs"); @@ -7,9 +8,14 @@ export const handleClockIn = async (driver: WebDriver) => { 5000 ); + asyncDelay(2000); + const clockInButton = driver.findElement( By.xpath('//a[text()="Web Clock-In"]') ); + console.log("===================================="); + console.log("clockInButton", clockInButton); + console.log("===================================="); await clockInButton.click(); const closeLocationPopupIdentifier = By.xpath(