Compare commits
No commits in common. "06cc89f76279d6b6d59d30e9194badc98b229b46" and "db30129c3028b730be5e79f00c50d5cb5b79972f" have entirely different histories.
06cc89f762
...
db30129c30
@ -25,8 +25,6 @@ jobs:
|
|||||||
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
|
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
|
||||||
DB_DIRECTORY: ${{ vars.DB_DIRECTORY }}
|
DB_DIRECTORY: ${{ vars.DB_DIRECTORY }}
|
||||||
DB_FILENAME: ${{ vars.DB_FILENAME }}
|
DB_FILENAME: ${{ vars.DB_FILENAME }}
|
||||||
TRANSACTION_RELATIVE_FROM_DATE: ${{ vars.TRANSACTION_RELATIVE_FROM_DATE }}
|
|
||||||
TRANSACTION_RELATIVE_TO_DATE: ${{ vars.TRANSACTION_RELATIVE_TO_DATE }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
|
@ -21,9 +21,8 @@ services:
|
|||||||
- TRANSACTION_RELATIVE_FROM_DATE
|
- TRANSACTION_RELATIVE_FROM_DATE
|
||||||
- TRANSACTION_RELATIVE_TO_DATE
|
- TRANSACTION_RELATIVE_TO_DATE
|
||||||
volumes:
|
volumes:
|
||||||
- cache:/${ACTUAL_DATA_DIR:-.cache}
|
# TODO CACHE directory in volume?
|
||||||
- data:/${DB_DIRECTORY:-data}
|
- data:/${DB_DIRECTORY}
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
cache:
|
|
||||||
data:
|
data:
|
||||||
|
@ -50,21 +50,6 @@ export class ActualImpl implements Actual {
|
|||||||
return new ActualImpl()
|
return new ActualImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to connect then immediatly shutsdown the connection
|
|
||||||
* @exception error If connection fails
|
|
||||||
*/
|
|
||||||
static async testConnection(): Promise<void> {
|
|
||||||
let actual: Actual | undefined
|
|
||||||
logger.info("Testing ActualBudget connection")
|
|
||||||
try {
|
|
||||||
actual = await ActualImpl.init()
|
|
||||||
} finally {
|
|
||||||
await actual?.shutdown()
|
|
||||||
logger.info("Finished testing ActualBudget connection")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async importTransactions(
|
async importTransactions(
|
||||||
accountId: UUID,
|
accountId: UUID,
|
||||||
transactions: Iterable<ActualTransaction>,
|
transactions: Iterable<ActualTransaction>,
|
||||||
|
26
src/main.ts
26
src/main.ts
@ -22,10 +22,7 @@ import dayjs from "dayjs"
|
|||||||
// TODO store last fetched date in db, and refetch from that date, if app has been offline for some time
|
// TODO store last fetched date in db, and refetch from that date, if app has been offline for some time
|
||||||
// TODO do not fetch if saturday or sunday
|
// TODO do not fetch if saturday or sunday
|
||||||
|
|
||||||
export async function moveTransactions(
|
export async function daily(actual: Actual, bank: Bank): Promise<void> {
|
||||||
actual: Actual,
|
|
||||||
bank: Bank,
|
|
||||||
): Promise<void> {
|
|
||||||
// Fetch transactions from the bank
|
// Fetch transactions from the bank
|
||||||
const actualTransactions = await bank.fetchTransactions(
|
const actualTransactions = await bank.fetchTransactions(
|
||||||
relativeInterval(),
|
relativeInterval(),
|
||||||
@ -66,6 +63,7 @@ async function main(): Promise<void> {
|
|||||||
|
|
||||||
createDirsIfMissing(ACTUAL_DATA_DIR, DB_DIRECTORY)
|
createDirsIfMissing(ACTUAL_DATA_DIR, DB_DIRECTORY)
|
||||||
|
|
||||||
|
const actual = await ActualImpl.init()
|
||||||
const databaseFilePath = `${DB_DIRECTORY}/${DB_FILENAME}.sqlite`
|
const databaseFilePath = `${DB_DIRECTORY}/${DB_FILENAME}.sqlite`
|
||||||
const db = createDb(databaseFilePath)
|
const db = createDb(databaseFilePath)
|
||||||
logger.info(`Started Sqlite database at '${databaseFilePath}'`)
|
logger.info(`Started Sqlite database at '${databaseFilePath}'`)
|
||||||
@ -78,33 +76,25 @@ async function main(): Promise<void> {
|
|||||||
|
|
||||||
let cronJob: CronJob | undefined
|
let cronJob: CronJob | undefined
|
||||||
if (process.env.ONCE) {
|
if (process.env.ONCE) {
|
||||||
const actual = await ActualImpl.init()
|
|
||||||
try {
|
try {
|
||||||
return await moveTransactions(actual, bank)
|
return await daily(actual, bank)
|
||||||
} finally {
|
} finally {
|
||||||
await actual.shutdown()
|
|
||||||
await shutdown()
|
await shutdown()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
await ActualImpl.testConnection()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Waiting for CronJob to start")
|
logger.info("Waiting for CRON job to start")
|
||||||
let actual: Actual | undefined
|
// TODO init and shutdown resources when job runs?
|
||||||
try {
|
try {
|
||||||
cronJob = cronJobDaily(async () => {
|
cronJob = cronJobDaily(async () => await daily(actual, bank))
|
||||||
actual = await ActualImpl.init()
|
|
||||||
await moveTransactions(actual, bank)
|
|
||||||
})
|
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
logger.error(exception, "Caught exception at CronJob, shutting down!")
|
logger.error(exception, "Caught exception at daily job, shutting down!")
|
||||||
await shutdown()
|
await shutdown()
|
||||||
} finally {
|
|
||||||
await actual?.shutdown()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shutdown(): Promise<void> {
|
async function shutdown(): Promise<void> {
|
||||||
logger.info("Shutting down, Bye!")
|
logger.info("Shutting down, Bye!")
|
||||||
|
await actual.shutdown()
|
||||||
db.close()
|
db.close()
|
||||||
cronJob?.stop()
|
cronJob?.stop()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { describe, it } from "@jest/globals"
|
import { describe, it } from "@jest/globals"
|
||||||
|
|
||||||
import { moveTransactions } from "@/main.ts"
|
import { daily } from "@/main.ts"
|
||||||
import { ActualImpl } from "@/actual.ts"
|
import { ActualImpl } from "@/actual.ts"
|
||||||
import { BankStub } from "./stubs/bankStub.ts"
|
import { BankStub } from "./stubs/bankStub.ts"
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ import { BankStub } from "./stubs/bankStub.ts"
|
|||||||
describe("Main logic of the application", () => {
|
describe("Main logic of the application", () => {
|
||||||
it("should import the transactions to Actual Budget", async () => {
|
it("should import the transactions to Actual Budget", async () => {
|
||||||
const actual = await ActualImpl.init()
|
const actual = await ActualImpl.init()
|
||||||
await moveTransactions(actual, new BankStub())
|
await daily(actual, new BankStub())
|
||||||
await actual.shutdown()
|
await actual.shutdown()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user