or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli.mdflask-integration.mdindex.md

flask-integration.mddocs/

0

# Flask Integration

1

2

Flask blueprint for embedding RQ Dashboard into existing Flask applications. Provides complete web interface with HTML views and REST API endpoints for monitoring RQ queues, jobs, and workers.

3

4

## Capabilities

5

6

### Blueprint Registration

7

8

Main Flask blueprint providing the complete RQ Dashboard web interface.

9

10

```python { .api }

11

blueprint: Blueprint

12

"""

13

Main Flask blueprint for RQ Dashboard web interface.

14

15

Blueprint name: "rq_dashboard"

16

Includes templates and static files for web interface.

17

"""

18

```

19

20

Basic integration:

21

```python

22

from flask import Flask

23

from rq_dashboard import blueprint

24

25

app = Flask(__name__)

26

app.register_blueprint(blueprint, url_prefix='/rq')

27

```

28

29

### Configuration Setup

30

31

Default configuration settings for Flask applications.

32

33

```python { .api }

34

default_settings: object

35

"""

36

Default Flask configuration settings.

37

Contains DEBUG = False and other basic settings.

38

"""

39

```

40

41

Usage:

42

```python

43

from flask import Flask

44

from rq_dashboard import blueprint, default_settings

45

46

app = Flask(__name__)

47

app.config.from_object(default_settings)

48

app.config['RQ_DASHBOARD_REDIS_URL'] = 'redis://localhost:6379'

49

app.register_blueprint(blueprint)

50

```

51

52

### Redis Connection Setup

53

54

Establishes Redis connections for RQ operations within Flask applications.

55

56

```python { .api }

57

def setup_rq_connection(current_app):

58

"""

59

Set up Redis connection for RQ operations.

60

61

Configures Redis connection based on RQ_DASHBOARD_REDIS_URL setting.

62

Supports single Redis instance or multiple instances for monitoring.

63

Handles Redis Sentinel configurations.

64

65

Args:

66

current_app: Flask application instance with configuration

67

68

Raises:

69

RuntimeError: If no Redis configuration is provided

70

"""

71

```

72

73

### Configuration Management

74

75

Configuration container for RQ Dashboard settings and serialization.

76

77

```python { .api }

78

class Config:

79

"""

80

Configuration container for RQ Dashboard settings.

81

82

Attributes:

83

serializer: RQ serializer instance (default: DefaultSerializer)

84

"""

85

serializer: Any

86

```

87

88

Global configuration instance:

89

```python { .api }

90

config: Config

91

"""Global configuration instance for RQ Dashboard."""

92

```

93

94

## HTML Routes

95

96

### Queue Management Views

97

98

```python { .api }

99

def queues_overview(instance_number):

100

"""

101

Display queues overview page.

102

103

Args:

104

instance_number: Redis instance index (0-based)

105

106

Returns:

107

Response: HTML page showing all queues with counts and links

108

"""

109

110

def jobs_overview(instance_number, queue_name, registry_name, per_page, order, page):

111

"""

112

Display jobs overview page with pagination.

113

114

Args:

115

instance_number: Redis instance index

116

queue_name: Name of the queue to display

117

registry_name: Registry type ('queued', 'failed', 'finished', etc.)

118

per_page: Number of jobs per page

119

order: Sort order ('asc' or 'desc')

120

page: Page number (1-based)

121

122

Returns:

123

Response: HTML page showing jobs list with pagination

124

"""

125

126

def job_view(instance_number, job_id):

127

"""

128

Display individual job details page.

129

130

Args:

131

instance_number: Redis instance index

132

job_id: Unique identifier for the job

133

134

Returns:

135

Response: HTML page showing detailed job information

136

"""

137

```

138

139

### Worker Management Views

140

141

```python { .api }

142

def workers_overview(instance_number):

143

"""

144

Display workers overview page.

145

146

Args:

147

instance_number: Redis instance index

148

149

Returns:

150

Response: HTML page showing all workers with status and statistics

151

"""

152

```

153

154

## JSON API Endpoints

155

156

### Data Retrieval

157

158

```python { .api }

159

def list_queues(instance_number):

160

"""

161

Get all queues as JSON.

162

163

Args:

164

instance_number: Redis instance index

165

166

Returns:

167

dict: JSON response with queues data including counts and URLs

168

"""

169

170

def list_jobs(instance_number, queue_name, registry_name, per_page, order, page):

171

"""

172

Get jobs list as JSON with pagination.

173

174

Args:

175

instance_number: Redis instance index

176

queue_name: Name of the queue

177

registry_name: Registry type

178

per_page: Jobs per page

179

order: Sort order

180

page: Page number

181

182

Returns:

183

dict: JSON response with jobs data and pagination info

184

"""

185

186

def job_info(instance_number, job_id):

187

"""

188

Get detailed job information as JSON.

189

190

Args:

191

instance_number: Redis instance index

192

job_id: Job identifier

193

194

Returns:

195

dict: JSON response with complete job details

196

"""

197

198

def list_workers(instance_number):

199

"""

200

Get all workers as JSON.

201

202

Args:

203

instance_number: Redis instance index

204

205

Returns:

206

dict: JSON response with workers data including status and statistics

207

"""

208

```

209

210

### Job Management Actions

211

212

```python { .api }

213

def delete_job_view(job_id, registry=None):

214

"""

215

Delete a specific job (POST endpoint).

216

217

Args:

218

job_id: Job identifier to delete

219

registry: Optional registry instance for cleanup

220

221

Returns:

222

dict: JSON response with operation status

223

"""

224

225

def requeue_job_view(job_id):

226

"""

227

Requeue a specific job (POST endpoint).

228

229

Args:

230

job_id: Job identifier to requeue

231

232

Returns:

233

dict: JSON response with operation status

234

"""

235

236

def requeue_all(queue_name):

237

"""

238

Requeue all failed jobs in a queue (GET/POST endpoint).

239

240

Args:

241

queue_name: Name of the queue to requeue jobs from

242

243

Returns:

244

dict: JSON response with operation status and count of requeued jobs

245

"""

246

```

247

248

### Queue Management Actions

249

250

```python { .api }

251

def empty_queue(queue_name, registry_name):

252

"""

253

Empty a queue or registry (POST endpoint).

254

255

Args:

256

queue_name: Name of the queue

257

registry_name: Registry type to empty

258

259

Returns:

260

dict: JSON response with operation status

261

"""

262

263

def compact_queue(queue_name):

264

"""

265

Compact a queue to remove completed jobs (POST endpoint).

266

267

Args:

268

queue_name: Name of the queue to compact

269

270

Returns:

271

dict: JSON response with operation status

272

"""

273

```

274

275

## Integration Examples

276

277

### Basic Integration

278

279

```python

280

from flask import Flask

281

from rq_dashboard import blueprint, default_settings

282

283

app = Flask(__name__)

284

285

# Apply default configuration

286

app.config.from_object(default_settings)

287

288

# Configure Redis connection

289

app.config['RQ_DASHBOARD_REDIS_URL'] = 'redis://localhost:6379'

290

291

# Register blueprint

292

app.register_blueprint(blueprint, url_prefix='/rq')

293

294

if __name__ == '__main__':

295

app.run(debug=True)

296

```

297

298

### Multiple Redis Instances

299

300

```python

301

from flask import Flask

302

from rq_dashboard import blueprint, default_settings

303

304

app = Flask(__name__)

305

app.config.from_object(default_settings)

306

307

# Configure multiple Redis instances

308

app.config['RQ_DASHBOARD_REDIS_URL'] = [

309

'redis://redis1:6379',

310

'redis://redis2:6379',

311

'redis://redis3:6379'

312

]

313

314

app.register_blueprint(blueprint, url_prefix='/monitoring/rq')

315

```

316

317

### With Authentication

318

319

```python

320

from flask import Flask, request, Response

321

from rq_dashboard import blueprint, default_settings

322

323

app = Flask(__name__)

324

app.config.from_object(default_settings)

325

app.config['RQ_DASHBOARD_REDIS_URL'] = 'redis://localhost:6379'

326

327

# Add authentication to blueprint

328

@blueprint.before_request

329

def require_auth():

330

auth = request.authorization

331

if not auth or auth.username != 'admin' or auth.password != 'secret':

332

return Response(

333

'Authentication required',

334

401,

335

{'WWW-Authenticate': 'Basic realm="RQ Dashboard"'}

336

)

337

338

app.register_blueprint(blueprint, url_prefix='/rq')

339

```

340

341

### Custom Configuration

342

343

```python

344

from flask import Flask

345

from rq_dashboard import blueprint, default_settings

346

from rq_dashboard.web import setup_rq_connection

347

348

app = Flask(__name__)

349

app.config.from_object(default_settings)

350

351

# Custom configuration

352

app.config.update({

353

'RQ_DASHBOARD_REDIS_URL': 'redis://localhost:6379',

354

'RQ_DASHBOARD_POLL_INTERVAL': 5000, # 5 seconds

355

'RQ_DASHBOARD_DISABLE_DELETE': True, # Disable job deletion

356

})

357

358

# Setup Redis connection

359

setup_rq_connection(app)

360

361

app.register_blueprint(blueprint)

362

```

363

364

## Configuration Options

365

366

### Required Settings

367

368

```python

369

# Single Redis instance

370

app.config['RQ_DASHBOARD_REDIS_URL'] = 'redis://localhost:6379'

371

372

# Multiple Redis instances

373

app.config['RQ_DASHBOARD_REDIS_URL'] = [

374

'redis://localhost:6379',

375

'redis://localhost:6380'

376

]

377

```

378

379

### Optional Settings

380

381

```python

382

# Polling interval in milliseconds (default: 2500)

383

app.config['RQ_DASHBOARD_POLL_INTERVAL'] = 5000

384

385

# Disable delete operations (default: False)

386

app.config['RQ_DASHBOARD_DISABLE_DELETE'] = True

387

388

# Redis Sentinel password (optional)

389

app.config['RQ_DASHBOARD_REDIS_SENTINEL_PASSWORD'] = 'sentinel_password'

390

391

# Redis instance password (optional)

392

app.config['RQ_DASHBOARD_REDIS_PASSWORD'] = 'redis_password'

393

```

394

395

## URL Structure

396

397

When registered with `url_prefix='/rq'`:

398

399

- `/rq/` - Main queues overview

400

- `/rq/0/view/queues` - Queues for Redis instance 0

401

- `/rq/0/view/workers` - Workers for Redis instance 0

402

- `/rq/0/view/jobs` - Jobs overview

403

- `/rq/0/data/queues.json` - Queues data API

404

- `/rq/job/{job_id}/delete` - Delete job action

405

- `/rq/job/{job_id}/requeue` - Requeue job action