kr / beanstalkd

Beanstalk is a simple, fast work queue.

This URL has Read+Write access

beanstalkd / job.h
100644 72 lines (54 sloc) 1.811 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* job.h - a job in the queue */
 
/* Copyright (C) 2007 Keith Rarick and Philotic Inc.
 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
 
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
 
#ifndef job_h
#define job_h
 
#include <time.h>
 
typedef struct job *job;
typedef int(*job_cmp_fn)(job, job);
 
#include "tube.h"
 
#define JOB_STATE_INVALID 0
#define JOB_STATE_READY 1
#define JOB_STATE_RESERVED 2
#define JOB_STATE_BURIED 3
#define JOB_STATE_DELAYED 4
 
struct job {
    job prev, next; /* linked list of jobs */
    unsigned long long int id;
    unsigned int pri;
    unsigned int delay;
    unsigned int ttr;
    int body_size;
    time_t creation;
    time_t deadline;
    unsigned int timeout_ct;
    unsigned int release_ct;
    unsigned int bury_ct;
    unsigned int kick_ct;
    tube tube;
    char state;
    char body[];
};
 
job allocate_job(int body_size);
job make_job(unsigned int pri, unsigned int delay, unsigned int ttr,
             int body_size, tube tube);
void job_free(job j);
 
int job_pri_cmp(job a, job b);
int job_delay_cmp(job a, job b);
 
job job_copy(job j);
 
const char * job_state(job j);
 
int job_list_any_p(job head);
job job_remove(job j);
void job_insert(job head, job j);
 
unsigned long long int total_jobs();
 
#endif /*job_h*/