Merge lp:~brianaker/gearmand/1063648 into lp:gearmand

Proposed by Brian Aker on 2013-08-16
Status: Merged
Merged at revision: 860
Proposed branch: lp:~brianaker/gearmand/1063648
Merge into: lp:gearmand
Diff against target: 139 lines (+48/-1)
3 files modified
libgearman/interface/worker.hpp (+13/-1)
libgearman/worker.cc (+15/-0)
tests/libgearman-1.0/worker_test.cc (+20/-0)
To merge this branch: bzr merge lp:~brianaker/gearmand/1063648
Reviewer Review Type Date Requested Status
Tangent Trunk 2013-08-16 Pending
Review via email: mp+180497@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libgearman/interface/worker.hpp'
2--- libgearman/interface/worker.hpp 2013-07-13 22:59:44 +0000
3+++ libgearman/interface/worker.hpp 2013-08-16 08:33:09 +0000
4@@ -49,6 +49,7 @@
5 bool grab_uniq;
6 bool grab_all;
7 bool timeout_return;
8+ bool _in_work;
9
10 Options() :
11 non_blocking(false),
12@@ -56,7 +57,8 @@
13 change(false),
14 grab_uniq(true),
15 grab_all(true),
16- timeout_return(false)
17+ timeout_return(false),
18+ _in_work(false)
19 { }
20 } options;
21 enum gearman_worker_state_t state;
22@@ -142,6 +144,16 @@
23 universal.options._ssl= ssl_;
24 }
25
26+ bool in_work() const
27+ {
28+ return options._in_work;
29+ }
30+
31+ void in_work(bool in_work_)
32+ {
33+ options._in_work= in_work_;
34+ }
35+
36 bool has_identifier() const
37 {
38 return universal.has_identifier();
39
40=== modified file 'libgearman/worker.cc'
41--- libgearman/worker.cc 2013-08-05 22:43:13 +0000
42+++ libgearman/worker.cc 2013-08-16 08:33:09 +0000
43@@ -656,6 +656,7 @@
44 Worker* worker= worker_shell->impl();
45 struct _worker_function_st *function;
46 uint32_t active;
47+ bool no_job= false;
48
49 gearman_return_t unused;
50 if (not ret_ptr)
51@@ -842,6 +843,7 @@
52 if (worker->job()->impl()->assigned.command == GEARMAN_COMMAND_NO_JOB or
53 worker->job()->impl()->assigned.command == GEARMAN_COMMAND_OPTION_RES)
54 {
55+ no_job= true;
56 gearman_packet_free(&(worker->job()->impl()->assigned));
57 break;
58 }
59@@ -861,6 +863,12 @@
60 }
61 }
62
63+ if (worker->in_work() == false and no_job)
64+ {
65+ *ret_ptr= GEARMAN_NO_JOBS;
66+ break;
67+ }
68+
69 case GEARMAN_WORKER_STATE_PRE_SLEEP:
70 for (worker->con= (&worker->universal)->con_list; worker->con;
71 worker->con= worker->con->next_connection())
72@@ -937,6 +945,11 @@
73
74 break;
75 }
76+
77+ if (*ret_ptr == GEARMAN_NO_JOBS)
78+ {
79+ break;
80+ }
81 }
82 }
83
84@@ -1038,8 +1051,10 @@
85 {
86 case GEARMAN_WORKER_WORK_UNIVERSAL_GRAB_JOB:
87 {
88+ worker->in_work(true);
89 gearman_return_t ret;
90 worker->work_job(gearman_worker_grab_job(worker->shell(), NULL, &ret));
91+ worker->in_work(false);
92
93 if (gearman_failed(ret))
94 {
95
96=== modified file 'tests/libgearman-1.0/worker_test.cc'
97--- tests/libgearman-1.0/worker_test.cc 2013-08-11 05:40:05 +0000
98+++ tests/libgearman-1.0/worker_test.cc 2013-08-16 08:33:09 +0000
99@@ -148,6 +148,20 @@
100 return TEST_SUCCESS;
101 }
102
103+static test_return_t gearman_worker_grab_job_TEST(void *)
104+{
105+ libgearman::Worker worker(libtest::default_port());
106+
107+ ASSERT_EQ(gearman_worker_register(&worker, __func__, 0), GEARMAN_SUCCESS);
108+
109+ gearman_return_t ret;
110+ gearman_job_st* job= gearman_worker_grab_job(&worker, NULL, &ret);
111+ ASSERT_NULL(job);
112+ ASSERT_EQ(GEARMAN_NO_JOBS, ret);
113+
114+ return TEST_SUCCESS;
115+}
116+
117 static test_return_t gearman_worker_free_TEST(void *)
118 {
119 gearman_worker_free(NULL);
120@@ -1599,6 +1613,11 @@
121 {0, 0, 0}
122 };
123
124+test_st gearman_worker_grab_job_TESTS[] ={
125+ {"gearman_worker_grab_job(NO_JOBS)", 0, gearman_worker_grab_job_TEST },
126+ {0, 0, 0}
127+};
128+
129 test_st gearman_worker_st_NULL_invocation_TESTS[] ={
130 {"gearman_worker_free()", 0, gearman_worker_free_TEST },
131 {"gearman_worker_error()", 0, gearman_worker_error_TEST },
132@@ -1619,6 +1638,7 @@
133 {"worker", 0, 0, worker_TESTS},
134 {"worker defaults", 0, 0, worker_defaults},
135 {"null gearman_worker_st invocation", 0, 0, gearman_worker_st_NULL_invocation_TESTS },
136+ {"gearman_worker_grab_job()", 0, 0, gearman_worker_grab_job_TESTS },
137 {"gearman_worker_set_identifier()", 0, 0, gearman_worker_set_identifier_TESTS},
138 {0, 0, 0, 0}
139 };

Subscribers

People subscribed via source and target branches

to all changes: