aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/runner/runner.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 14:55:10 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch)
tree226d3dd1565b0bb56588897af3b8530e6216e96b /server/models/runner/runner.ts
parent6bcb854cdea8688a32240bc5719c7d139806e00b (diff)
downloadPeerTube-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/runner/runner.ts')
-rw-r--r--server/models/runner/runner.ts112
1 files changed, 112 insertions, 0 deletions
diff --git a/server/models/runner/runner.ts b/server/models/runner/runner.ts
new file mode 100644
index 000000000..1ef0018b4
--- /dev/null
+++ b/server/models/runner/runner.ts
@@ -0,0 +1,112 @@
1import { FindOptions } from 'sequelize'
2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { MRunner } from '@server/types/models/runners'
4import { Runner } from '@shared/models'
5import { AttributesOnly } from '@shared/typescript-utils'
6import { getSort } from '../shared'
7import { RunnerRegistrationTokenModel } from './runner-registration-token'
8import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
9
10@Table({
11 tableName: 'runner',
12 indexes: [
13 {
14 fields: [ 'runnerToken' ],
15 unique: true
16 },
17 {
18 fields: [ 'runnerRegistrationTokenId' ]
19 }
20 ]
21})
22export class RunnerModel extends Model<Partial<AttributesOnly<RunnerModel>>> {
23
24 // Used to identify the appropriate runner when it uses the runner REST API
25 @AllowNull(false)
26 @Column
27 runnerToken: string
28
29 @AllowNull(false)
30 @Column
31 name: string
32
33 @AllowNull(true)
34 @Column(DataType.STRING(CONSTRAINTS_FIELDS.RUNNERS.DESCRIPTION.max))
35 description: string
36
37 @AllowNull(false)
38 @Column
39 lastContact: Date
40
41 @AllowNull(false)
42 @Column
43 ip: string
44
45 @CreatedAt
46 createdAt: Date
47
48 @UpdatedAt
49 updatedAt: Date
50
51 @ForeignKey(() => RunnerRegistrationTokenModel)
52 @Column
53 runnerRegistrationTokenId: number
54
55 @BelongsTo(() => RunnerRegistrationTokenModel, {
56 foreignKey: {
57 allowNull: false
58 },
59 onDelete: 'cascade'
60 })
61 RunnerRegistrationToken: RunnerRegistrationTokenModel
62
63 // ---------------------------------------------------------------------------
64
65 static load (id: number) {
66 return RunnerModel.findByPk(id)
67 }
68
69 static loadByToken (runnerToken: string) {
70 const query = {
71 where: { runnerToken }
72 }
73
74 return RunnerModel.findOne(query)
75 }
76
77 static listForApi (options: {
78 start: number
79 count: number
80 sort: string
81 }) {
82 const { start, count, sort } = options
83
84 const query: FindOptions = {
85 offset: start,
86 limit: count,
87 order: getSort(sort)
88 }
89
90 return Promise.all([
91 RunnerModel.count(query),
92 RunnerModel.findAll<MRunner>(query)
93 ]).then(([ total, data ]) => ({ total, data }))
94 }
95
96 // ---------------------------------------------------------------------------
97
98 toFormattedJSON (this: MRunner): Runner {
99 return {
100 id: this.id,
101
102 name: this.name,
103 description: this.description,
104
105 ip: this.ip,
106 lastContact: this.lastContact,
107
108 createdAt: this.createdAt,
109 updatedAt: this.updatedAt
110 }
111 }
112}