Update comment.
[beanstalkd.git] / job.h
blob33e516db5eab8a800aedb835e4ce80e0a4512489
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 <time.h>
24 typedef struct job *job;
25 typedef int(*job_cmp_fn)(job, job);
27 #include "tube.h"
29 #define JOB_STATE_INVALID 0
30 #define JOB_STATE_READY 1
31 #define JOB_STATE_RESERVED 2
32 #define JOB_STATE_BURIED 3
33 #define JOB_STATE_DELAYED 4
34 #define JOB_STATE_COPY 5
36 /* If you modify this struct, you MUST increment binlog format version in
37 * binlog.c. */
38 struct job {
40 /* persistent fields; these get written to the binlog */
41 unsigned long long int id;
42 unsigned int pri;
43 unsigned int delay;
44 unsigned int ttr;
45 int body_size;
46 time_t creation;
47 time_t deadline;
48 unsigned int reserve_ct;
49 unsigned int timeout_ct;
50 unsigned int release_ct;
51 unsigned int bury_ct;
52 unsigned int kick_ct;
53 char state;
55 /* bookeeping fields; these are in-memory only */
56 char pad[6];
57 tube tube;
58 job prev, next; /* linked list of jobs */
59 job ht_next; /* Next job in a hash table list */
60 size_t heap_index; /* where is this job in its current heap */
61 void *binlog;
62 void *reserver;
63 size_t reserved_binlog_space;
65 /* variable-size job data; written separately to the binlog */
66 char body[];
69 #define make_job(pri,delay,ttr,body_size,tube) make_job_with_id(pri,delay,ttr,body_size,tube,0)
71 job allocate_job(int body_size);
72 job make_job_with_id(unsigned int pri, unsigned int delay, unsigned int ttr,
73 int body_size, tube tube, unsigned long long id);
74 void job_free(job j);
76 /* Lookup a job by job ID */
77 job job_find(unsigned long long int job_id);
79 int job_pri_cmp(job a, job b);
80 int job_delay_cmp(job a, job b);
82 job job_copy(job j);
84 const char * job_state(job j);
86 int job_list_any_p(job head);
87 job job_remove(job j);
88 void job_insert(job head, job j);
90 unsigned long long int total_jobs();
92 /* for unit tests */
93 size_t get_all_jobs_used();
95 void job_init();
97 #endif /*job_h*/