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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
use Error;
use ;
use Path;
use FromStr;
use Tz;
use Lazy;
use Value;
use crateget_http_jobs;
use crateJobs;
/// The lazy-initialized `Jobs` instance.
///
/// This static variable holds the lazily initialized `Jobs` instance using the `Lazy` type
/// from the `once_cell` crate. The `Jobs` instance is initialized by calling the `init_read_jobs`
/// function. The initialization is performed lazily, meaning that the `init_read_jobs` function
/// is only called the first time the `JOBS` variable is accessed.
static JOBS: = new;
/// Returns a reference to the initialized `Jobs` instance.
///
/// This function returns a reference to the lazily initialized `Jobs` instance. The instance is
/// created and initialized by the `init_read_jobs` function. Subsequent calls to this function
/// will return a reference to the same `Jobs` instance without re-initializing it.
///
/// # Returns
///
/// A reference to the initialized `Jobs` instance.
/// Initializes and returns the `Jobs` instance by reading the configuration.
///
/// This function reads the configuration, parses the timezone and HTTP jobs,
/// and returns a fully initialized `Jobs` instance. If any errors occur during
/// the process, appropriate error messages are printed to stderr and the program
/// exits with a non-zero status code.
///
/// # Returns
///
/// The initialized `Jobs` instance.
///
/// # Panics
///
/// This function can panic under the following conditions:
///
/// * Failed to read the configure file.
/// * Failed to parse the timezone field or the timezone is invalid.
/// * Failed to parse the HTTP jobs.
///
/// Retrieves the configuration from a file.
///
/// This function reads the content from the file and determines the file format based on the file extension.
/// It supports JSON, YAML, and YML file formats.
///
/// # Errors
///
/// This function may return an error if:
/// - The file doesn't exist or cannot be read.
/// - The file format is not supported.
/// - There are multiple files with conflicting extensions.
/// - An error occurs while parsing the file content.
///
/// # Returns
///
/// The configuration value extracted from the file.
///
/// # Examples
///
/// ```
/// match get_value() {
/// Ok(config) => {
/// // Use the configuration
/// println!("Configuration: {:?}", config);
/// },
/// Err(err) => {
/// eprintln!("Failed to retrieve configuration: {}", err);
/// },
/// }
/// ```
/// Reads the content of the specified file.
///
/// # Arguments
///
/// * `file_path` - The path of the file to read.
///
/// # Errors
///
/// Returns an error if:
/// * The file fails to be read.
///
/// # Examples
///
/// ```rust
/// # use std::error::Error;
/// #
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let content = read_file("./jobs.json")?;
/// println!("File content: {}", content);
/// #
/// # Ok(())
/// # }
/// ```
/// Retrieves the content of the 'jobs' file.
///
/// This function searches for the 'jobs' file in different formats (JSON, YAML, YML) in the current directory.
/// It returns the content of the first file found, and determines the file format based on the file extension.
///
/// # Errors
///
/// This function may return an error if:
/// - No 'jobs' file is found.
/// - Multiple 'jobs' files with conflicting extensions are found.
/// - An error occurs while reading or processing the file.
///
/// # Returns
///
/// The content of the 'jobs' file, wrapped in a `FileContent` enum that represents the file format.
///
/// # Examples
///
/// ```
/// match get_jobs_file_content() {
/// Ok(content) => {
/// // Process the content
/// println!("File content: {:?}", content);
/// },
/// Err(err) => {
/// eprintln!("Failed to retrieve 'jobs' file content: {}", err);
/// },
/// }
/// ```
/// Represents the content of a file in different formats (JSON, YAML, YML).
///
/// The `FileContent` enum has three variants, each corresponding to a specific file format.
///
/// - `Json`: Represents the file content as a JSON string.
/// - `Yaml`: Represents the file content as a YAML string.
/// - `Yml`: Represents the file content as a YML string.
///
/// # Examples
///
/// ```
/// let json_content = FileContent::Json("{ \"name\": \"John\", \"age\": 30 }".into());
/// let yaml_content = FileContent::Yaml("name: John\nage: 30".into());
/// let yml_content = FileContent::Yml("name: John\nage: 30".into());
///
/// match json_content {
/// FileContent::Json(content) => {
/// // Process JSON content
/// println!("JSON content: {}", content);
/// },
/// _ => unreachable!(),
/// }
/// ```
/// Get the file extension from the given file path.
/// Returns `Some(extension)` if the file has an extension, or `None` if it doesn't.
///
/// # Arguments
///
/// * `file` - A string representing the file path.
///
/// # Examples
///
/// ```
/// let file_path = "example.json";
/// let extension = get_file_extension(file_path);
/// println!("File extension: {:?}", extension);
/// ```