1
0
mirror of https://github.com/laurent22/joplin.git synced 2026-04-18 19:42:23 +02:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Laurent Cozic e73f17f1af update 2026-04-17 08:34:55 +01:00
3 changed files with 20 additions and 36 deletions
+5 -1
View File
@@ -31,7 +31,11 @@ const subRoutes: Record<string, RouteHandler> = {
try {
await ctx.joplin.models.user().sendResetPasswordEmail(fields.email || '');
} catch (error) {
logger.warn(`Could not send reset email for ${fields.email}`, error);
if (error instanceof ErrorNotFound) {
logger.info(`Could not send reset email for ${fields.email}`, error);
} else {
logger.warn(`Could not send reset email for ${fields.email}`, error);
}
}
confirmationMessage = 'If we have an account that matches your email, you should receive an email with instructions on how to reset your password shortly.';
+14 -28
View File
@@ -1,6 +1,5 @@
import Logger from '@joplin/utils/Logger';
import newModelFactory, { Models } from '../models/factory';
import { DbConnection, disconnectDb } from '../db';
import { Models } from '../models/factory';
import { Config, Env } from '../utils/types';
import BaseService from './BaseService';
import { Event, EventType, TaskId, TaskState } from './database/types';
@@ -68,29 +67,16 @@ export default class TaskService extends BaseService {
private tasks_: Tasks = {};
private services_: Services;
private taskStateModels_: Models;
private taskStateDb_: DbConnection;
public constructor(env: Env, models: Models, config: Config, services: Services, taskStateDb: DbConnection = null) {
public constructor(env: Env, models: Models, config: Config, services: Services) {
super(env, models, config);
this.services_ = services;
this.taskStateDb_ = taskStateDb;
this.taskStateModels_ = taskStateDb ? newModelFactory(taskStateDb, taskStateDb, config) : models;
}
public async destroy() {
await super.destroy();
if (this.taskStateDb_) {
await disconnectDb(this.taskStateDb_);
this.taskStateDb_ = null;
this.taskStateModels_ = null;
}
}
public async registerTask(task: Task) {
if (this.tasks_[task.id]) throw new Error(`Already a task with this ID: ${task.id}`);
this.tasks_[task.id] = task;
await this.taskStateModels_.taskState().init(task.id);
await this.models.taskState().init(task.id);
}
public async registerTasks(tasks: Task[]) {
@@ -106,7 +92,7 @@ export default class TaskService extends BaseService {
}
public async taskStates(ids: TaskId[]): Promise<TaskState[]> {
return this.taskStateModels_.taskState().loadByTaskIds(ids);
return this.models.taskState().loadByTaskIds(ids);
}
public async taskState(id: TaskId): Promise<TaskState> {
@@ -117,17 +103,17 @@ export default class TaskService extends BaseService {
public async taskLastEvents(id: TaskId): Promise<TaskEvents> {
return {
taskStarted: await this.taskStateModels_.event().lastEventByTypeAndName(EventType.TaskStarted, id.toString()),
taskCompleted: await this.taskStateModels_.event().lastEventByTypeAndName(EventType.TaskCompleted, id.toString()),
taskStarted: await this.models.event().lastEventByTypeAndName(EventType.TaskStarted, id.toString()),
taskCompleted: await this.models.event().lastEventByTypeAndName(EventType.TaskCompleted, id.toString()),
};
}
public async resetInterruptedTasks() {
const taskStates = await this.taskStateModels_.taskState().all();
const taskStates = await this.models.taskState().all();
for (const taskState of taskStates) {
if (taskState.running) {
logger.warn(`Found a task that was in running state: ${this.taskDisplayString(taskState.task_id)} - resetting it.`);
await this.taskStateModels_.taskState().stop(taskState.task_id);
await this.models.taskState().stop(taskState.task_id);
}
}
}
@@ -144,7 +130,7 @@ export default class TaskService extends BaseService {
public async runTask(id: TaskId, runType: RunType) {
const displayString = this.taskDisplayString(id);
const taskState = await this.taskStateModels_.taskState().loadByTaskId(id);
const taskState = await this.models.taskState().loadByTaskId(id);
if (!taskState) throw new Error(`Invalid task: ${id}: ${runType}`);
if (!taskState.enabled) {
@@ -152,11 +138,11 @@ export default class TaskService extends BaseService {
return;
}
await this.taskStateModels_.taskState().start(id);
await this.models.taskState().start(id);
const startTime = Date.now();
await this.taskStateModels_.event().create(EventType.TaskStarted, id.toString());
await this.models.event().create(EventType.TaskStarted, id.toString());
try {
logger.info(`Running ${displayString} (${runTypeToString(runType)})...`);
@@ -165,14 +151,14 @@ export default class TaskService extends BaseService {
logger.error(`On ${displayString}`, error);
}
await this.taskStateModels_.taskState().stop(id);
await this.taskStateModels_.event().create(EventType.TaskCompleted, id.toString());
await this.models.taskState().stop(id);
await this.models.event().create(EventType.TaskCompleted, id.toString());
logger.info(`Completed ${this.taskDisplayString(id)} in ${Date.now() - startTime}ms`);
}
public async enableTask(taskId: TaskId, enabled = true) {
await this.taskStateModels_.taskState().enable(taskId, enabled);
await this.models.taskState().enable(taskId, enabled);
}
public async runInBackground() {
@@ -1,5 +1,4 @@
import { Models } from '../models/factory';
import { connectDb } from '../db';
import { TaskId } from '../services/database/types';
import TaskService, { Task, taskIdToLabel } from '../services/TaskService';
import { Services } from '../services/types';
@@ -8,12 +7,7 @@ import { Config, Env } from './types';
import { Day } from './time';
export default async function(env: Env, models: Models, config: Config, services: Services): Promise<TaskService> {
// In production, use a separate DB connection pool for task state
// management so that it is not affected by failed transactions in the
// main connection pool. In dev/test, we reuse the main connection to
// avoid exhausting Postgres connection slots in CI.
const taskStateDb = env === Env.Prod ? await connectDb({ ...config.database, maxConnections: 1 }) : null;
const taskService = new TaskService(env, models, config, services, taskStateDb);
const taskService = new TaskService(env, models, config, services);
let tasks: Task[] = [
{