-
Notifications
You must be signed in to change notification settings - Fork 9
/
jobserver.cpp
71 lines (65 loc) · 1.16 KB
/
jobserver.cpp
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
#ifndef _MPROCME_JOBSERVER_CPP
#define _MPROCME_JOBSERVER_CPP
#include <stdlib.h>
#include <string.h>
#include "processmanager.h"
#include "jobserver.h"
Jobserver::Jobserver()
{
}
Jobserver::~Jobserver()
{
}
xpipe * Jobserver::get_send_pipe()
{
return m_send;
}
void Jobserver::set_send_pipe(xpipe &xpipe)
{
m_send=&xpipe;
}
xpipe * Jobserver::get_recv_pipe()
{
return m_recv;
}
void Jobserver::set_recv_pipe(xpipe &xpipe)
{
m_recv=&xpipe;
}
void Jobserver::load_job()
{
char type[4][32]={"PAYBY","XZ","HFGP","XSD"};
static long i=0;
srand(time(NULL));
int r=(rand()/RAND_MAX)*4;
strcpy(rec.billtype,type[r]);
rec.recid=++i;
}
void Jobserver::run()
{
Processmanager pm;
pm.init_num_process(2);
pm.start();
long jobscount=30;
string is_worker_ready;
int i=1;
while (true){
//collect Jobs
jobscount=30*(i++);
if (i>100){
cout<<"Jobserver stop"<<endl;
exit(0);
}
pm.set_jobs_count(jobscount);
pm.adjust_proc_num();
m_recv->recv(is_worker_ready);
if (is_worker_ready=="OK"){
//publish job
load_job();
m_send->send(&rec,sizeof(struct REC));
cout<<"Jobserver:publish job-"<<rec.billtype
<<"-"<<rec.recid<<endl;
}
}
}
#endif