-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueRetry.cpp
125 lines (113 loc) · 2.55 KB
/
QueueRetry.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include"QueueRetry.h"
#include <iostream>
#include <fstream>
using namespace std;
QueueRetry::QueueRetry() : fileName("rsync_fail_log.sh"), retryInterval(7200)
{
}
void QueueRetry::SetRetryInfo(string file_name, int time)
{
fileName = file_name;
retryInterval = time;
ofstream out;
out.open(fileName.c_str(), ofstream::app);
out.close();
string command = "chmod 777 " + fileName;
system(command.c_str());
}
bool QueueRetry::empty()
{
boost::mutex::scoped_lock lock(queue_mutex);
return que.empty();
}
string QueueRetry::pop()
{
boost::mutex::scoped_lock lock(queue_mutex);
while (que.empty())
{
cond.wait(lock);
}
string command = que.back();
que.pop_back();
return command;
}
bool QueueRetry::time_wait_pop(string& command, boost::system_time timeout)
{
boost::mutex::scoped_lock lock(queue_mutex);
if (que.empty())
{
if (!cond.timed_wait(lock, timeout))
{
return false;
}
}
command = que.back();
que.pop_back();
return true;
}
void QueueRetry::pop_back()
{
boost::mutex::scoped_lock lock(queue_mutex);
while (que.empty())
{
cond.wait(lock);
}
que.pop_back();
}
string QueueRetry::back()
{
boost::mutex::scoped_lock lock(queue_mutex);
while (que.empty())
{
cond.wait(lock);
}
string command = que.back();
return command;
}
int QueueRetry::push(string command)
{
boost::mutex::scoped_lock lock(queue_mutex);
if (que.size() >= MAX_LENGTH_FAILQUEUE)
{
ErrorLog(command);
return 0;
}
cond.notify_all();
que.push_front(command);
return 1;
}
void QueueRetry::ErrorLog(string command)
{
ofstream out;
out.open(fileName.c_str(), ofstream::app);
out << command << endl;
out.close();
}
void QueueRetry::printdeque()
{
boost::mutex::scoped_lock lock(queue_mutex);
int cre = 0;
int del = 0;
if (que.empty())
{
cout << "empty retry Queue" << endl;
} else
{
for (std::deque<string>::iterator itrt = que.begin(); itrt < que.end(); itrt++)
{
std::cout << "Queue Retry: " << (*itrt) << "\n";
if ((*itrt).find("--delete") != string::npos)
{
del++;
} else
{
cre++;
}
}
cout << "Queue Retry: " << endl;
cout << "amount: " << que.size() << "\t";
cout << "create: " << cre << "\t";
cout << "delete: " << del << "\t";
std::cout << endl << endl << endl;
}
}