|
1 |
| -use anyhow; |
2 |
| -use parsnip::{ |
3 |
| - self, broker::Broker, messages::Message, messages::ResultMessage, task::Signature, task::Task, |
4 |
| - worker::Worker, |
5 |
| -}; |
6 |
| -use std::collections::LinkedList; |
7 |
| -use std::sync::RwLock; |
8 |
| - |
9 |
| -struct InMemoryTestBroker { |
10 |
| - task_results: RwLock<Vec<ResultMessage>>, |
11 |
| - queue: RwLock<LinkedList<Message>>, |
12 |
| -} |
13 |
| - |
14 |
| -impl InMemoryTestBroker { |
15 |
| - fn new() -> Self { |
16 |
| - Self { |
17 |
| - task_results: RwLock::new(Vec::new()), |
18 |
| - queue: RwLock::new(LinkedList::new()), |
19 |
| - } |
20 |
| - } |
21 |
| -} |
22 |
| - |
23 |
| -impl Broker for InMemoryTestBroker { |
24 |
| - fn push_message(&self, message: &Message) -> anyhow::Result<()> { |
25 |
| - self.queue |
26 |
| - .write() |
27 |
| - .expect("Failed to aquire lock") |
28 |
| - .push_back(message.clone()); |
29 |
| - Ok(()) |
30 |
| - } |
31 |
| - |
32 |
| - fn pop_message(&self) -> anyhow::Result<Option<Message>> { |
33 |
| - match self |
34 |
| - .queue |
35 |
| - .write() |
36 |
| - .expect("Failed to aquire lock") |
37 |
| - .pop_front() |
38 |
| - { |
39 |
| - Some(message) => Ok(Some(message)), |
40 |
| - None => Ok(None), |
41 |
| - } |
42 |
| - } |
43 |
| - |
44 |
| - fn store_result(&self, result_message: ResultMessage) -> anyhow::Result<()> { |
45 |
| - self.task_results |
46 |
| - .write() |
47 |
| - .expect("Failed to aquire lock") |
48 |
| - .push(result_message.clone()); |
49 |
| - Ok(()) |
50 |
| - } |
51 |
| -} |
52 |
| - |
53 |
| -struct HelloWorldTask { |
54 |
| - called_with_signature: Signature<Self>, |
55 |
| -} |
56 |
| - |
57 |
| -impl Task for HelloWorldTask { |
58 |
| - type ArgumentType = (); |
59 |
| - type ReturnType = (); |
60 |
| - |
61 |
| - const ID: &'static str = "HelloWorldTask"; |
62 |
| - |
63 |
| - fn from_signature(signature: Signature<Self>) -> Self { |
64 |
| - Self { |
65 |
| - called_with_signature: signature, |
66 |
| - } |
67 |
| - } |
68 |
| - |
69 |
| - fn run(_: &Self::ArgumentType) -> Self::ReturnType { |
70 |
| - println!("Hello, World!"); |
71 |
| - } |
72 |
| - |
73 |
| - fn signature(&self) -> &Signature<Self> { |
74 |
| - &self.called_with_signature |
75 |
| - } |
76 |
| -} |
77 |
| - |
78 |
| -fn main() -> Result<(), anyhow::Error> { |
79 |
| - let mut broker = InMemoryTestBroker::new(); |
80 |
| - let mut app = parsnip::App::new(&mut broker); |
81 |
| - app.register_task::<HelloWorldTask>(); |
82 |
| - |
83 |
| - let worker = Worker::new(&app); |
84 |
| - |
85 |
| - app.queue_task::<HelloWorldTask>(())?; |
86 |
| - worker.take_first_task_in_queue()?; |
87 |
| - |
88 |
| - Ok(()) |
| 1 | +fn main() { |
| 2 | + println!("This binary is for the Parnsip CLI. Nothing to see here yet...") |
89 | 3 | }
|
0 commit comments