diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 14:55:10 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch) | |
tree | 226d3dd1565b0bb56588897af3b8530e6216e96b /server/models/shared/update.ts | |
parent | 6bcb854cdea8688a32240bc5719c7d139806e00b (diff) | |
download | PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip |
Implement remote runner jobs in server
Move ffmpeg functions to @shared
Diffstat (limited to 'server/models/shared/update.ts')
-rw-r--r-- | server/models/shared/update.ts | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/server/models/shared/update.ts b/server/models/shared/update.ts index d02c4535d..96db43730 100644 --- a/server/models/shared/update.ts +++ b/server/models/shared/update.ts | |||
@@ -1,22 +1,32 @@ | |||
1 | import { QueryTypes, Sequelize, Transaction } from 'sequelize' | 1 | import { QueryTypes, Sequelize, Transaction } from 'sequelize' |
2 | 2 | ||
3 | const updating = new Set<string>() | ||
4 | |||
3 | // Sequelize always skip the update if we only update updatedAt field | 5 | // Sequelize always skip the update if we only update updatedAt field |
4 | function setAsUpdated (options: { | 6 | async function setAsUpdated (options: { |
5 | sequelize: Sequelize | 7 | sequelize: Sequelize |
6 | table: string | 8 | table: string |
7 | id: number | 9 | id: number |
8 | transaction?: Transaction | 10 | transaction?: Transaction |
9 | }) { | 11 | }) { |
10 | const { sequelize, table, id, transaction } = options | 12 | const { sequelize, table, id, transaction } = options |
13 | const key = table + '-' + id | ||
14 | |||
15 | if (updating.has(key)) return | ||
16 | updating.add(key) | ||
11 | 17 | ||
12 | return sequelize.query( | 18 | try { |
13 | `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`, | 19 | await sequelize.query( |
14 | { | 20 | `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`, |
15 | replacements: { table, id, updatedAt: new Date() }, | 21 | { |
16 | type: QueryTypes.UPDATE, | 22 | replacements: { table, id, updatedAt: new Date() }, |
17 | transaction | 23 | type: QueryTypes.UPDATE, |
18 | } | 24 | transaction |
19 | ) | 25 | } |
26 | ) | ||
27 | } finally { | ||
28 | updating.delete(key) | ||
29 | } | ||
20 | } | 30 | } |
21 | 31 | ||
22 | export { | 32 | export { |