Merge commit 'abh/master'; commit 'gbarr/truncate-binlog'
[beanstalkd.git] / job.h
blobae2bc27fc296feb97e9274a66cec91f73cbd862e
1 /* job.h - a job in the queue */
3 /* Copyright (C) 2007 Keith Rarick and Philotic Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef job_h
20 #define job_h
22 #include "config.h"
24 #if HAVE_STDINT_H
25 # include <stdint.h>
26 #endif /* else we get int types from config.h */
28 #include "util.h"
30 typedef struct job *job;
31 typedef int(*job_cmp_fn)(job, job);
33 #include "tube.h"
35 #define JOB_STATE_INVALID 0
36 #define JOB_STATE_READY 1
37 #define JOB_STATE_RESERVED 2
38 #define JOB_STATE_BURIED 3
39 #define JOB_STATE_DELAYED 4
40 #define JOB_STATE_COPY 5
42 /* If you modify this struct, you MUST increment binlog format version in
43 * binlog.c. */
44 struct job {
46 /* persistent fields; these get written to the binlog */
47 uint64_t id;
48 uint32_t pri;
49 usec delay;
50 usec ttr;
51 int32_t body_size;
52 usec created_at;
53 usec deadline_at;
54 uint32_t reserve_ct;
55 uint32_t timeout_ct;
56 uint32_t release_ct;
57 uint32_t bury_ct;
58 uint32_t kick_ct;
59 uint8_t state;
61 /* bookeeping fields; these are in-memory only */
62 char pad[6];
63 tube tube;
64 job prev, next; /* linked list of jobs */
65 job ht_next; /* Next job in a hash table list */
66 size_t heap_index; /* where is this job in its current heap */
67 void *binlog;
68 void *reserver;
69 size_t reserved_binlog_space;
71 /* variable-size job data; written separately to the binlog */
72 char body[];
75 #define make_job(pri,delay,ttr,body_size,tube) make_job_with_id(pri,delay,ttr,body_size,tube,0)
77 job allocate_job(int body_size);
78 job make_job_with_id(unsigned int pri, usec delay, usec ttr,
79 int body_size, tube tube, uint64_t id);
80 void job_free(job j);
82 /* Lookup a job by job ID */
83 job job_find(uint64_t job_id);
85 int job_pri_cmp(job a, job b);
86 int job_delay_cmp(job a, job b);
88 job job_copy(job j);
90 const char * job_state(job j);
92 int job_list_any_p(job head);
93 job job_remove(job j);
94 void job_insert(job head, job j);
96 uint64_t total_jobs();
98 /* for unit tests */
99 size_t get_all_jobs_used();
101 void job_init();
103 #endif /*job_h*/