croservices / cro Goto Github PK
View Code? Open in Web Editor NEWDevelopment tools for building services and distributed systems in Raku using the Cro libraries.
Home Page: https://cro.services/
License: Artistic License 2.0
Development tools for building services and distributed systems in Raku using the Cro libraries.
Home Page: https://cro.services/
License: Artistic License 2.0
$ uname -v
Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64
$ perl6 --version
This is Rakudo version 2018.12-281-g46409c070 built on MoarVM version 2018.12-45-ga9d02578a
implementing Perl 6.d.
==> Testing: cro:ver<0.8.0>
# Check service up attempt 1: connection refused
# Check service up attempt 2: connection refused
# Check service up attempt 3: connection refused
# Check service up attempt 4: connection refused
# Check service up attempt 5: connection refused
# Check service up attempt 6: connection refused
# Check service up attempt 7: connection refused
# Check service up attempt 8: connection refused
# Check service up attempt 9: connection refused
# Check service up attempt 10: connection refused
# Check service up attempt 11: connection refused
# Check service up attempt 12: connection refused
# Check service up attempt 13: connection refused
# Check service up attempt 14: connection refused
# Check service up attempt 15: connection refused
# Check service up attempt 16: connection refused
# Check service up attempt 17: connection refused
# Check service up attempt 18: connection refused
# Check service up attempt 19: connection refused
# Check service up attempt 20: connection refused
# Check service up attempt 21: connection refused
# Check service up attempt 22: connection refused
# Check service up attempt 23: connection refused
# Check service up attempt 24: connection refused
# Check service up attempt 25: connection refused
# Check service up attempt 26: connection refused
# Check service up attempt 27: connection refused
# Check service up attempt 28: connection refused
# Check service up attempt 29: connection refused
# Check service up attempt 30: connection refused
# Check service up attempt 31: connection refused
# Check service up attempt 32: connection refused
# Check service up attempt 33: connection refused
# Check service up attempt 34: connection refused
# Check service up attempt 35: connection refused
# Check service up attempt 36: connection refused
# Check service up attempt 37: connection refused
# Check service up attempt 38: connection refused
# Check service up attempt 39: connection refused
# Check service up attempt 40: connection refused
# Failed test 'Could call the started service'
# at t/tools-runner.t line 63
# Failed test 'Got expected resposne from service'
# at t/tools-runner.t line 64
# expected: 'Service 1 OK'
# got: (Any)
^ just hangs at this point
In "http://cro.services/docs/reference/cro-http-router" there is a
section named "Accessing the Cro::HTTP::Request instance" with this example:
my $app = route {
get -> {
say "Request headers:";
for request.headers {
say "{.name}: {.value}";
}
}
}
When I try to use it I get the following exception:
Request headers:
Host: localhost
Connection: close
Cannot unbox a type object (Cro::HTTP::Response::StatusCode) to int.
in block at /usr/local/rakudo.d/share/perl6/site/sources/9E898BFBAC00FE9363AE6D27527AD02192D19DDD (Cro::HTTP::ResponseSerializer) line 13
in block at /usr/local/rakudo.d/share/perl6/site/sources/88931D797A7005CE2FD56A6EF6A37BBD2E8D6CFA (Cro::HTTP::Internal) line 45
in block at /usr/local/rakudo.d/share/perl6/site/sources/1DC86B9F9A31CA5BEE35765E177159BAEDB91AAA (Cro::HTTP::Router) line 82
System: Debian 8, 64-bit.
$ perl6 -v
This is Rakudo version 2017.08-110-g5f33506 built on MoarVM version 2017.08.1-156-g49b90b9
implementing Perl 6.c.
Complete code is at gist: https://gist.github.com/tbrowder/fc5d4c628561451a9c9ea0ef1f7a2a93
There is a rakudo ticket with more details, but I think it's a good idea to keep another ticket here so that we can discuss cro-specific things. Also, this ticket may need to be moved to another cro repo.
To create a stub, I ran (with the default options):
cro stub http 0 stub
To run it:
cd stub
cro run
The error I get is:
An operation first awaited:
in sub run-services at D:\rakudo\share\perl6\site\sources\75AA87B0B3D14DE5E701638495D50F0610D7A87C (Cro::Tools::CLI) line 251
in sub MAIN at D:\rakudo\share\perl6\site\sources\75AA87B0B3D14DE5E701638495D50F0610D7A87C (Cro::Tools::CLI) line 222
in block at D:\rakudo\share\perl6\site\resources\50C277F38919A198F096E266302A29B056579D44 line 1
in sub MAIN at D:\rakudo\share\perl6\site\bin\cro line 2
in block at D:\rakudo\share\perl6\site\bin\cro line 2Died with the exception:
no such file or directory
in sub run-services at D:\rakudo\share\perl6\site\sources\75AA87B0B3D14DE5E701638495D50F0610D7A87C (Cro::Tools::CLI) line 251
in sub MAIN at D:\rakudo\share\perl6\site\sources\75AA87B0B3D14DE5E701638495D50F0610D7A87C (Cro::Tools::CLI) line 222
in block at D:\rakudo\share\perl6\site\resources\50C277F38919A198F096E266302A29B056579D44 line 1
in sub MAIN at D:\rakudo\share\perl6\site\bin\cro line 2
in block at D:\rakudo\share\perl6\site\bin\cro line 2
My perl is Rakudo version 2017.09-355-g27131ed8d built on MoarVM version 2017.09.1-575-gd4e230a6. Doing the same process works fine on Linux, though the Linux server is running an older version of Rakudo.
If you cro stub
an HTTPS service using cro 0.7.1, the service.p6
file includes the line:
certificate-file => %*ENV<{$env-name}_TLS_CERT>
(Note that $env-name
did not get properly interpolated into the generated code.)
Without ssl enabled it seems "almost" ok
This is Rakudo version 2018.02.1-99-g6117647 built on MoarVM version 2018.02-24-gd7f4387
===> Installing: cro:ver<0.7.6>
Potential difficulties:
Asked to remove 12 spaces, but the shortest indent is 0 spaces
at /home/jnthn/dev/cro/cro/site#sources/D44F060F1508953EA54C88CF61E79D8A11D3BFDA (Cro::Tools::Template::ReactReduxSPA):144
------> CODE⏏<EOL>
Asked to remove 12 spaces, but the shortest indent is 1 spaces
at /home/jnthn/dev/cro/cro/site#sources/D44F060F1508953EA54C88CF61E79D8A11D3BFDA (Cro::Tools::Template::ReactReduxSPA):144
------> CODE⏏<EOL>
1 bin/ script [cro] installed to:
/home/jnthn/dev/MoarVM/install/share/perl6/site/bin
The documentation for cro stub
templates should include at least one example of extending an existing template. For example, the http
template could be extended to set up .gitignore
and the extra config files needed for webpack, npm, etc. to make a template that more completely stubs out a React/Redux SPA like the big tutorial page builds.
Thank you for addressing #4 quickly; however, the published example does not work:
Type check failed in binding to parameter '$application'; expected Cro::Transform but got Bool (Bool::True)
Since the example now defines the routes in a variable called $application, the constructor should now read:
:host<localhost>, :port<10000>, :application($application);
The stub for zmq is generating a Dockerfile that uses a base image that doesn’t have the libzmq installed
https://cro.services/docs/approach#Composition mentions reply
, but it throws an error, as it has to be transformer
instead.
See: http://cro.services/docs/reference/cro-http-client
In this page, I found the method $resp.body-blob
or $resp.body-text
, but couldn't find the method $resp.body
.
I think some of the users generally use the method $resp.body
rather than the former two methods, since this example sets JSON parser when initializing a client.
Because SSL up to version 3.0 is already deprecated by RFC7568 I'd suggest renaming all classes to TLS to reflect that it's new code which supports currently security standards.
I'd supply ;-) a pull-request if you want.
Okay, so after removing everything and starting from building and installing Rakudo Perl 6, followed by zef --verbose install IO::Socket::Async::SSL WebSocket Digest::SHA1::Native Crypt::Random IO::Path::ChildSecure HTTP::HPACK
, I was able to get to this point (previously Cro::HTTP
was failing):
% zef install cro (master|✔)
===> Searching for: cro
===> Searching for missing dependencies: Cro::WebSocket
===> Searching for missing dependencies: Cro::HTTP
===> Searching for missing dependencies: Cro::Core, Cro::TLS
===> Testing: Cro::Core:ver<0.7>
===> Testing [OK] for Cro::Core:ver<0.7>
===> Testing: Cro::TLS:ver<0.7>
===> Testing [OK] for Cro::TLS:ver<0.7>
===> Testing: Cro::HTTP:ver<0.7>
===> Testing [OK] for Cro::HTTP:ver<0.7>
===> Testing: Cro::WebSocket:ver<0.7>
===> Testing [OK] for Cro::WebSocket:ver<0.7>
===> Testing: cro:ver<0.7>
WARNING: unhandled Failure detected in DESTROY. If you meant to ignore it, you can mark it as handled by calling .Bool, .so, .not, or .defined methods. The Failure was:
No such symbol 'Cro::Tools::LinkTemplate::HTTPS'
in sub get-available-templates at /Users/cal/.zef/store/cro.git/aed600e44c27c58ddf16f2b4a6f8e1f7e95c9f6e/lib/Cro/Tools/TemplateLocator.pm6 (Cro::Tools::TemplateLocator) line 33
in sub print-endpoint at /Users/cal/.zef/store/cro.git/aed600e44c27c58ddf16f2b4a6f8e1f7e95c9f6e/lib/Cro/Tools/Link/Editor.pm6 (Cro::Tools::Link::Editor) line 87
in sub add-link at /Users/cal/.zef/store/cro.git/aed600e44c27c58ddf16f2b4a6f8e1f7e95c9f6e/lib/Cro/Tools/Link/Editor.pm6 (Cro::Tools::Link::Editor) line 65
in block <unit> at t/tools-link-editor.t line 10
# Check service up attempt 1: connection refused
# Check service up attempt 2: connection refused
# Check service up attempt 3: connection refused
# Check service up attempt 4: connection refused
# Check service up attempt 5: connection refused
# Check service up attempt 6: connection refused
# Check service up attempt 7: connection refused
# Check service up attempt 8: connection refused
# Check service up attempt 9: connection refused
# Check service up attempt 10: connection refused
# Check service up attempt 11: connection refused
# Check service up attempt 12: connection refused
# Check service up attempt 13: connection refused
# Check service up attempt 14: connection refused
# Check service up attempt 15: connection refused
# Check service up attempt 16: connection refused
# Check service up attempt 17: connection refused
# Check service up attempt 18: connection refused
# Check service up attempt 19: connection refused
# Check service up attempt 20: connection refused
# Failed test 'Could call the started service'
# at t/tools-runner.t line 62
# Failed test 'Got expected resposne from service'
# at t/tools-runner.t line 63
# expected: 'Service 1 OK'
# got: (Any)
# Failed test 'Was not on STDERR'
# at t/tools-runner.t line 67
# Failed test 'Got log line mentioning status code'
# at t/tools-runner.t line 68
# Check service up attempt 1: connection refused
# Check service up attempt 2: connection refused
# Check service up attempt 3: connection refused
# Check service up attempt 4: connection refused
# Check service up attempt 5: connection refused
# Check service up attempt 6: connection refused
# Check service up attempt 7: connection refused
# Check service up attempt 8: connection refused
# Check service up attempt 9: connection refused
# Check service up attempt 10: connection refused
# Check service up attempt 11: connection refused
# Check service up attempt 12: connection refused
# Check service up attempt 13: connection refused
# Check service up attempt 14: connection refused
# Check service up attempt 15: connection refused
# Check service up attempt 16: connection refused
# Check service up attempt 17: connection refused
# Check service up attempt 18: connection refused
# Check service up attempt 19: connection refused
# Check service up attempt 20: connection refused
# Failed test 'Could call the restarted service'
# at t/tools-runner.t line 79
# Failed test 'Got response indicating new service running'
# at t/tools-runner.t line 80
# expected: 'Service 1 UPDATED'
# got: (Any)
# Failed test 'Was not on STDERR'
# at t/tools-runner.t line 84
# Failed test 'Got log line mentioning status code'
# at t/tools-runner.t line 85
# Looks like you failed 8 tests of 20
# Failed test 'First service has correct path'
# at t/tools-services.t line 27
# expected: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T//cro-test-1737632532897610565445853975597039156628/nested/service2'
# got: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T/cro-test-1737632532897610565445853975597039156628/nested/service2'
# Failed test 'Second service has correct path'
# at t/tools-services.t line 32
# expected: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T//cro-test-1737632532897610565445853975597039156628/service1'
# got: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T/cro-test-1737632532897610565445853975597039156628/service1'
# Failed test 'Third service has correct path'
# at t/tools-services.t line 47
# expected: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T//cro-test-1737632532897610565445853975597039156628/service3'
# got: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T/cro-test-1737632532897610565445853975597039156628/service3'
# Failed test 'Got notified of changed service source file'
# at t/tools-services.t line 69
# expected: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T//cro-test-1737632532897610565445853975597039156628/nested/service2/lib/Foo.pm6'
# got: '/var/folders/wr/pz8bs3nx2c515m09t5j4f_xr0000gn/T/cro-test-1737632532897610565445853975597039156628/nested/service2/lib/Foo.pm6'
# Looks like you failed 4 tests of 25
===> Testing [FAIL]: cro:ver<0.7>
Aborting due to test failure: cro:ver<0.7> (use --force-test to override)
in code at /Users/cal/local/share/perl6/site/sources/29769DA546CA5B55E3D2F7F8C9D20095C41CCF61 (Zef::Client) line 375
in method test at /Users/cal/local/share/perl6/site/sources/29769DA546CA5B55E3D2F7F8C9D20095C41CCF61 (Zef::Client) line 353
in code at /Users/cal/local/share/perl6/site/sources/29769DA546CA5B55E3D2F7F8C9D20095C41CCF61 (Zef::Client) line 530
in sub at /Users/cal/local/share/perl6/site/sources/29769DA546CA5B55E3D2F7F8C9D20095C41CCF61 (Zef::Client) line 527
in method install at /Users/cal/local/share/perl6/site/sources/29769DA546CA5B55E3D2F7F8C9D20095C41CCF61 (Zef::Client) line 633
in sub MAIN at /Users/cal/local/share/perl6/site/sources/3A2818F8A8CE2F1251F051B779AA0EC17DA2F72E (Zef::CLI) line 152
in block <unit> at /Users/cal/local/share/perl6/site/resources/91C74F08994E0006C3049614EF974F6E1A8EDF2D line 1
in sub MAIN at /Users/cal/local/share/perl6/site/bin/zef line 2
in block <unit> at /Users/cal/local/share/perl6/site/bin/zef line 2
perl6 version:
% perl6 -v (master|✔)
This is Rakudo version 2017.09-353-g1ea3297b2 built on MoarVM version 2017.09.1-575-gd4e230a6
implementing Perl 6.c.
% perl6 -v
This is Rakudo version 2017.08-136-gb30ac08 built on MoarVM version 2017.08.1-171-gcf95892
===> Searching for: cro
===> Updated cpan mirror: https://raw.githubusercontent.com/ugexe/Perl6-ecosystems/master/cpan.json
===> Found: cro:ver<0.7> [via Zef::Repository::Ecosystems<p6c>]
[..snip..]
===> Install [OK] for Cro::WebSocket:ver<0.7>
===> Installing: cro:ver<0.7>
===> Install [FAIL] for cro:ver<0.7>: ===SORRY!===
Could not find Cro::Tools::Link::Editor at line 1 in:
/home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site
/home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/vendor
/home/steve/.rakudobrew/moar-blead-nom/install/share/perl6
CompUnit::Repository::AbsolutePath<58049888>
CompUnit::Repository::NQP<37524456>
CompUnit::Repository::Perl5<37524496>
===> Updated p6c mirror: http://ecosystem-api.p6c.org/projects.json
===SORRY!===
Could not find Cro::Tools::Link::Editor at line 1 in:
/home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site
/home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/vendor
/home/steve/.rakudobrew/moar-blead-nom/install/share/perl6
CompUnit::Repository::AbsolutePath<58049888>
CompUnit::Repository::NQP<37524456>
CompUnit::Repository::Perl5<37524496>
in any at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/precomp/64F6B5F256CBC0E54DD9ABA281077E9BA84D8E55.1505474594.97788/E9/E98EEF837C2BEEB4C4EE270906957CB1C5DC8BAD line 1
in block at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/sources/E98EEF837C2BEEB4C4EE270906957CB1C5DC8BAD (Zef::Client) line 581
in any at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/precomp/64F6B5F256CBC0E54DD9ABA281077E9BA84D8E55.1505474594.97788/E9/E98EEF837C2BEEB4C4EE270906957CB1C5DC8BAD line 1
in block at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/sources/E98EEF837C2BEEB4C4EE270906957CB1C5DC8BAD (Zef::Client) line 589
in block at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/sources/E98EEF837C2BEEB4C4EE270906957CB1C5DC8BAD (Zef::Client) line 552
in sub at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/sources/E98EEF837C2BEEB4C4EE270906957CB1C5DC8BAD (Zef::Client) line 541
in method install at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/sources/E98EEF837C2BEEB4C4EE270906957CB1C5DC8BAD (Zef::Client) line 633
in sub MAIN at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/sources/E5C4501FC410C5FAD80CF4D0B6A252A4F928D633 (Zef::CLI) line 152
in block <unit> at /home/steve/.rakudobrew/moar-blead-nom/install/share/perl6/site/resources/A76807CE689F66BA252B3D85DF3EABA7AE381027 line 1
in sub MAIN at /home/steve/.rakudobrew/bin/../moar-blead-nom/install/share/perl6/site/bin/zef line 2
in block <unit> at /home/steve/.rakudobrew/bin/../moar-blead-nom/install/share/perl6/site/bin/zef line 2
I have had good success with the Cro Router and Server, but Cro::HTTP::Client gives me grief. Any request I have tried running results in a promise that is neither kept nor broken. e.g.
my $resp = await Cro::HTTP::Client.get('https://www.perl6.org/');
I am running Cro::Core:ver('0.7') with Rakudo 2017.08-59-g0bc1c8774 on Debian 9 in an EC2 instance.
I can ping the external site just fine from the command line.
I suppose that there may be something blocking rakudo from accessing the network, but the eternal hanging and no hint as to what is wrong seems to be a bad behavior.
Otherwise, this is a very neat project. Thank you!
If writing a client for a JSON API, it may become tedious to set the content type on every request.
After copy/pasting example I didn't noticed that Accept => 'application/json'
header is missing so server was returning text/html back. We should at least extend section with header => { Accept => ...
or even introduce Cro::HTTP::Client.new: accept => ...
as we have content-type
already. @jnthn, what do you think? Thx.
$ cro link my-http-service http-test-2 https
Unknown command
in sub MAIN at /home/jnthn/dev/MoarVM/install/share/perl6/site/sources/75AA87B0B3D14DE5E701638495D50F0610D7A87C (Cro::Tools::CLI) line 164
in block <unit> at /home/jnthn/dev/MoarVM/install/share/perl6/site/resources/DE7784E09AA7C90C649235C72C689A082FAC5189 line 1
in sub MAIN at /home/jnthn/dev/MoarVM/install/share/perl6/site/bin/cro line 2
in block <unit> at /home/jnthn/dev/MoarVM/install/share/perl6/site/bin/cro line 2
The stub for zmq is generating a META6 with dependency of Cro::ZMQ
that seems to not exist. Probably it should be Cro::ZeroMQ
$ cro link add my-http-service http-test-2 https
use Cro::HTTP::Client
my $client = Cro::HTTP::Client.new:
base-uri => "http://%*ENV<HTTP_TEST___HOST>:%*ENV<HTTP_TEST___PORT>/";
I think I'd probably put a line between the use
and the rest of the code, but then not indent the code.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04 LTS
Release: 18.04
Codename: bionic
Steps used to simulate the problem:
In the "Set up your routes, and serve them" example on http://mi.cro.services/ there's:
react whenever signal(SITINT) { $hello.stop; exit; }
That should probably be SIGINT
Cro looks awesome, and the documentation is pretty nice, but I could have used a a simple one-stop tutorial for how to get up and running, a page with something like the following (to be detailed)
Install Perl 6 (link to site and instructions) and zef (saying what that is)
Install Cro (using zef)
Hello World server app example source code
How to run the Hello server app
How to test that it works: localhost:10000, localhost:100000/greet/YourName
You're done!
Extra credit:
If you think this would be useful but don't want to write this, I could take a shot at it and submit it to you. Let me know.
-- a dummy
Provide an example to show how to get at an uploaded file.
Dynamic variables get lost inside of route HTTP method (get, post, etc.) routines:
use Cro::HTTP::Router;
use Cro::HTTP::Server;
my $*dyn = 'I am dynamic';
my $application = route {
say $*dyn; # works
{
say $*dyn; # works
}
say -> {
$*dyn; # works
}();
get -> {
content 'text/html', "{$*dyn}"; # Dynamic variable $*dyn not found
}
}
my Cro::Service $hello-service = Cro::HTTP::Server.new(
:host('localhost'), :port(8888), :$application
);
$hello-service.start;
react whenever signal(SIGINT) {
$hello-service.stop;
exit;
}
In the cro git repo, using commit fb251c5:
==========================8<---------------------------------
$ CRO_TRACE=1 zef test .
===> Testing: cro:ver('0.7')
# Check service up attempt 1: connection refused
# Check service up attempt 2: connection refused
# Check service up attempt 3: connection refused
[TRACE(anon 4)] Cro::HTTP::RequestSerializer EMIT Cro::TCP::Message.new(data => Blob[uint8].new(71,69,84,32,47,32,72,84,84,80,47,49,46,49,13,10,72,111,115,116,58,32,108,111,99,97,108,104,111,115,116,13,10,67,111,110,110,101,99,116,105,111,110,58,32,99,108,111,115,101,13,10,13,10), connection => Any)
[TRACE(anon 4)] Cro::TCP::Connector EMIT Cro::TCP::Message.new(data => Buf[uint8].new(72,84,84,80,47,49,46,49,32,50,48,48,32,79,75,13,10,67,111,110,116,101,110,116,45,116,121,112,101,58,32,116,101,120,116,47,112,108,97,105,110,59,32,99,104,97,114,115,101,116,61,117,116,102,45,56,13,10,67,111,110,116,101,110,116,45,108,101,110,103,116,104,58,32,49,50,13,10,13,10), connection => Any)
[TRACE(anon 4)] Cro::HTTP::ResponseParser EMIT Cro::HTTP::Response.new(request => Cro::HTTP::Request, status => 200, body-parser-selector => Cro::HTTP::BodyParserSelector::ResponseDefault, body-serializer-selector => Cro::HTTP::BodySerializerSelector::ResponseDefault, http-version => "1.1", http2-stream-id => Int)
[TRACE(anon 4)] Cro::HTTP::RequestSerializer DONE
[TRACE(anon 4)] Cro::TCP::Connector EMIT Cro::TCP::Message.new(data => Buf[uint8].new(83,101,114,118,105,99,101,32,49,32,79,75), connection => Any)
[TRACE(anon 4)] Cro::TCP::Connector DONE
[TRACE(anon 4)] Cro::HTTP::ResponseParser DONE
# Failed test 'Got an output message after request'
# at t/tools-runner.t line 63
# Actual type: Cro::Tools::Runner::Trace
No such method 'on-stderr' for invocant of type 'Cro::Tools::Runner::Trace'
in block at t/tools-runner.t line 64
===> Testing [FAIL]: cro:ver('0.7')
Aborting due to test failure: cro:ver('0.7') (use --force-test to override)
in code at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/sources/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 (Zef::Client) line 375
in method test at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/sources/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 (Zef::Client) line 353
in sub MAIN at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/sources/31FF9E8498781BF95868DF98AD861FCF1211BCC1 (Zef::CLI) line 38
in block at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/resources/0031ECC6124802A80F7B7B073C50D0A1694E3020 line 1
in sub MAIN at /home/sjn/.rakudobrew/bin/../moar-nom/install/share/perl6/site/bin/zef line 2
in block at /home/sjn/.rakudobrew/bin/../moar-nom/install/share/perl6/site/bin/zef line 2
==============================8<------------------
If I run without CRO_TRACE=1, the tests just hang.
$ perl6 -v
This is Rakudo version 2017.08-42-gf1b086308 built on MoarVM version 2017.08.1-19-g151a25634
implementing Perl 6.c.
In the "Set up your routes, and serve them" example on http://mi.cro.services/, the $app variable is created, but not referenced after that. It should probably be passed to the Cro::HTTP::Server.new constructor:
:host<localhost>, :port<10000>, :application($app);
At least, doing this allowed the example to work OK on Windows 10.
We should include this header in the example, or provide a way to construct the object and have the header generated.
See https://irclog.perlgeek.de/cro/2017-11-26#i_15497139 for more details.
Essentially, recursive directory watching is generally useful, and finicky to get right, so this sub should be pulled out of the class and made available generally (or even moved into the Perl 6 setting, with Cro-specific bits abstracted out).
Hi all, just started tinkering with cro and wanted to make a note about how I got it installed on Debian sid. I am using moar 2017.09, zef v0.1.30.
Debian package:
libssl1.0-dev
The zef install --/test cro
required installing specific versions of:
I installed those by cloning their respective repos and checkout out the required version, and installing.
Is there a simpler way to handle the Perl 6 modules versions and get a successful install only using zef install --/test cro
?
Installed the new version 0.7.4 and created a test project with cro stub.
Works fine. However, starting the app with "cro run" always fails with:
~/repos/tmp/testApp % cro run
An operation first awaited:
in sub run-services at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/sources/B14B9B56CCF50261CB1E1C25B049FC58D1F30474 (Cro::Tools::CLI) line 227
in sub MAIN at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/sources/B14B9B56CCF50261CB1E1C25B049FC58D1F30474 (Cro::Tools::CLI) line 198
in block <unit> at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/resources/8C896382B12DB78F2AEB19945D9B2168F70BBB2F line 1
in sub MAIN at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/bin/cro line 2
in block <unit> at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/bin/cro line 2
Died with the exception:
Cannot look up attributes in a Cro::Tools::CroFile type object
in sub run-services at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/sources/B14B9B56CCF50261CB1E1C25B049FC58D1F30474 (Cro::Tools::CLI) line 227
in sub MAIN at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/sources/B14B9B56CCF50261CB1E1C25B049FC58D1F30474 (Cro::Tools::CLI) line 198
in block <unit> at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/resources/8C896382B12DB78F2AEB19945D9B2168F70BBB2F line 1
in sub MAIN at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/bin/cro line 2
in block <unit> at /home/wolf/perl6/rakudo-star-2018.01/install/share/perl6/site/bin/cro line 2
First I encountered that with perl6 2017.10. So I installed 2018.01. Problem still exists.
Starting the service directly works flawlessly.
I see that you're adding some middlewares to Cro. Are there any plans for something like PSGI/Plack for Cro/Perl6, so that we can avoid the Web-Framework-Trap (c.f. Catalyst, Dancer, Mojo all implementing lot of in theory generic stuff (like Token/Session Handling, ...)) ?
I haven't tried cro (yet), so I'm not sure if cro is more like a web framework (Mojo/Dancer), or more a generic app framework that happens to work good with web, or an abstraction layer / toolkit I can use to build my own web apps (that will also include a significant non-web part (cronjobs, daemons, import/export scripts)
This questions is probably not an 'issue', but afaik there is no mailinglist?
Greetings,
domm
Only connecting is documented.
I run this:
$ cro stub http My::Experiment firsttry :websocket
...which produces the following output:
=============================8<------------------------
Stubbing a HTTP Service 'My::Experiment' in 'firsttry'...
WARNING: unhandled Failure detected in DESTROY. If you meant to ignore it, you can mark it as handled by calling .Bool, .so, .not, or .defined methods. The Failure was:
No such symbol 'Cro::Tools::Template::ZeroMQWorkerService'
in sub get-available-templates at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/sources/575A6116019092B74061842AEA0B5B597749E23B (Cro::Tools::TemplateLocator) line 31
in sub MAIN at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/sources/75AA87B0B3D14DE5E701638495D50F0610D7A87C (Cro::Tools::CLI) line 18
in block at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/resources/DE7784E09AA7C90C649235C72C689A082FAC5189 line 1
in sub MAIN at /home/sjn/.rakudobrew/bin/../moar-nom/install/share/perl6/site/bin/cro line 2
in block at /home/sjn/.rakudobrew/bin/../moar-nom/install/share/perl6/site/bin/cro line 2
WARNING: unhandled Failure detected in DESTROY. If you meant to ignore it, you can mark it as handled by calling .Bool, .so, .not, or .defined methods. The Failure was:
No such symbol 'Cro::Tools::Template::ZeroMQWorkSinkService'
in sub get-available-templates at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/sources/575A6116019092B74061842AEA0B5B597749E23B (Cro::Tools::TemplateLocator) line 31
in sub MAIN at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/sources/75AA87B0B3D14DE5E701638495D50F0610D7A87C (Cro::Tools::CLI) line 18
in block at /home/sjn/.rakudobrew/moar-nom/install/share/perl6/site/resources/DE7784E09AA7C90C649235C72C689A082FAC5189 line 1
in sub MAIN at /home/sjn/.rakudobrew/bin/../moar-nom/install/share/perl6/site/bin/cro line 2
in block at /home/sjn/.rakudobrew/bin/../moar-nom/install/share/perl6/site/bin/cro line 2
==============================8<---------------------------------
When using the example code below:
Tried with some other web-socket servers and the html example works as expected.
This is Rakudo version 2018.03-147-g232c664 built on MoarVM version 2018.03-68-ged4201e
implementing Perl 6.c.
Perl 6 code
#!/usr/bin/env perl6
use v6.c;
my $chat = Supplier.new;
use Cro::HTTP::Router;
use Cro::HTTP::Router::WebSocket;
use Cro::HTTP::Server;
my $app = route {
get -> 'chat' {
web-socket -> $incoming {
supply {
whenever $incoming -> $message {
$chat.emit("OK-"~(await $message.body-text));
}
whenever $chat -> $text {
emit $text;
}
}
}
}
};
say "BEGIN";
my $service = Cro::HTTP::Server.new: :host('127.0.0.1'), :port(8888), :application($app);
say "Start";
$service.start;
say "Listen";
react whenever signal(SIGINT) { say "GOT KILL INT.....EXIT"; $service.stop; exit; }
HTML client
<!doctype html>
<html>
<body>
<div id="terminal"><textarea id="area"></textarea></div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript">
var socket = new WebSocket('ws://127.0.0.1:8888/chat');
socket.onopen = function(){ console.log("opened"); test() };
socket.onclose = function(){ console.log("closed") };
socket.onmessage = function(ev){ $("#area").html(ev.data); };
socket.onerror = function(ev){ console.log("ERROR: " + ev.data) };
$(window).on('beforeunload', function(){
console.log("Close socket");
socket.close();
});
function test(){
setInterval(function(){ socket.send("PING");},10);
setTimeout(function(){for(var i=0; i<2000; i++){ for(var x=0; x<10; x++){ socket.send(i+":"+x) } }},100);
setTimeout(function(){for(var i=0; i<2000; i++){ for(var x=0; x<10; x++){ socket.send(i+":"+x) } }},100);
}
</script>
</body>
</html>
Is there an option, or planned option, to exclude directories from the cro run
/ cro trace
file monitoring? For example, it scans node_modules
and ,precomp
. This slows down startup and when using dynamic require
causes a cro
service restart.
$ perl6 -v
This is Rakudo version 2018.04-20-g7847768 built on MoarVM version 2018.04-34-g25f165a
implementing Perl 6.c.
$ lsb_release -a
LSB Version: core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: Ubuntu
Description: Ubuntu 12.04 LTS
Release: 12.04
Codename: precise
$ uname -a
Linux ZZZ 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ zef install cro
===> Searching for: cro
===> Found: cro:ver<0.7.5> [via Zef::Repository::Ecosystems<cpan>]
===> Dependencies: IO::Socket::Async::SSL, JSON::Fast, META6, Shell::Command, File::Find, Terminal::ANSIColor, OO::Monitors, YAMLish, Cro::WebSocket, Docker::File
===> Searching for missing dependencies: Cro::WebSocket
===> Found dependencies: Cro::WebSocket:ver<0.7.5> [via Zef::Repository::Ecosystems<cpan>]
===> Dependencies: Cro::HTTP, Base64, Digest::SHA1::Native, Crypt::Random, JSON::Fast
===> Searching for missing dependencies: Cro::HTTP
===> Found dependencies: Cro::HTTP:ver<0.7.5> [via Zef::Repository::Ecosystems<cpan>]
===> Dependencies: IO::Socket::Async::SSL, OO::Monitors, IO::Path::ChildSecure, Base64, HTTP::HPACK, Cro::Core, Cro::TLS, JSON::Fast, Crypt::Random, JSON::JWT, DateTime::Parse
===> Searching for missing dependencies: Cro::Core, Cro::TLS
===> Found dependencies: Cro::TLS:ver<0.7.5>, Cro::Core:ver<0.7.5> [via Zef::Repository::Ecosystems<cpan>]
===> Dependencies: Cro::Core, IO::Socket::Async::SSL
===> Fetching: cro
Fetching with plugin: Zef::Service::Shell::curl+{<anon|1>}
===> Fetching [OK]: cro:ver<0.7.5> to /home/zoffix/.zef/tmp/1526389807.27715.4584/cro-0.7.5.tar.gz
===> Fetching: Cro::WebSocket
Fetching with plugin: Zef::Service::Shell::curl+{<anon|1>}
===> Fetching [OK]: Cro::WebSocket:ver<0.7.5> to /home/zoffix/.zef/tmp/1526389809.27715.7513/cro-websocket-0.7.5.tar.gz
===> Fetching: Cro::HTTP
Fetching with plugin: Zef::Service::Shell::curl+{<anon|1>}
===> Fetching [OK]: Cro::HTTP:ver<0.7.5> to /home/zoffix/.zef/tmp/1526389810.27715.616/cro-http-0.7.5.tar.gz
===> Fetching: Cro::TLS
Fetching with plugin: Zef::Service::Shell::curl+{<anon|1>}
===> Fetching [OK]: Cro::TLS:ver<0.7.5> to /home/zoffix/.zef/tmp/1526389811.27715.5625/cro-tls-0.7.5.tar.gz
===> Fetching: Cro::Core
Fetching with plugin: Zef::Service::Shell::curl+{<anon|1>}
===> Fetching [OK]: Cro::Core:ver<0.7.5> to /home/zoffix/.zef/tmp/1526389811.27715.2157/cro-core-0.7.5.tar.gz
===> Extracting: cro
Extracting with plugin: Zef::Service::Shell::tar+{<anon|1>}
===> Extraction [OK]: cro to /home/zoffix/.zef/store/cro-0.7.5.tar.gz
===> Extracting: Cro::WebSocket
Extracting with plugin: Zef::Service::Shell::tar+{<anon|1>}
===> Extraction [OK]: Cro::WebSocket to /home/zoffix/.zef/store/cro-websocket-0.7.5.tar.gz
===> Extracting: Cro::HTTP
Extracting with plugin: Zef::Service::Shell::tar+{<anon|1>}
===> Extraction [OK]: Cro::HTTP to /home/zoffix/.zef/store/cro-http-0.7.5.tar.gz
===> Extracting: Cro::TLS
Extracting with plugin: Zef::Service::Shell::tar+{<anon|1>}
===> Extraction [OK]: Cro::TLS to /home/zoffix/.zef/store/cro-tls-0.7.5.tar.gz
===> Extracting: Cro::Core
Extracting with plugin: Zef::Service::Shell::tar+{<anon|1>}
===> Extraction [OK]: Cro::Core to /home/zoffix/.zef/store/cro-core-0.7.5.tar.gz
===> Filtering: cro:ver<0.7.5>
===> Filtering [OK] for cro:ver<0.7.5>
===> Filtering: Cro::WebSocket:ver<0.7.5>
===> Filtering [OK] for Cro::WebSocket:ver<0.7.5>
===> Filtering: Cro::HTTP:ver<0.7.5>
===> Filtering [OK] for Cro::HTTP:ver<0.7.5>
===> Filtering: Cro::TLS:ver<0.7.5>
===> Filtering [OK] for Cro::TLS:ver<0.7.5>
===> Filtering: Cro::Core:ver<0.7.5>
===> Filtering [OK] for Cro::Core:ver<0.7.5>
===> # SKIP: No need to build Cro::Core:ver<0.7.5>
===> # SKIP: No need to build Cro::TLS:ver<0.7.5>
===> # SKIP: No need to build Cro::HTTP:ver<0.7.5>
===> # SKIP: No need to build Cro::WebSocket:ver<0.7.5>
===> # SKIP: No need to build cro:ver<0.7.5>
===> Testing: Cro::Core:ver<0.7.5>
Testing with plugin: Zef::Service::Shell::prove+{<anon|1>}
t/composer.t ................ ok
t/connection-conditional.t .. ok
t/connection-state.t ........ ok
t/iri.t ..................... ok
t/mediatype.t ............... ok
t/message-with-body.t ....... ok
t/tcp.t ..................... ok
t/uri.t ..................... ok
All tests successful.
Files=8, Tests=1140, 13 wallclock secs ( 0.14 usr 0.02 sys + 12.06 cusr 0.59 csys = 12.81 CPU)
Result: PASS
===> Testing [OK] for Cro::Core:ver<0.7.5>
===> Testing: Cro::TLS:ver<0.7.5>
Testing with plugin: Zef::Service::Shell::prove+{<anon|1>}
t/tls.t .. ok
All tests successful.
Files=1, Tests=49, 11 wallclock secs ( 0.03 usr 0.00 sys + 9.57 cusr 0.46 csys = 10.06 CPU)
Result: PASS
===> Testing [OK] for Cro::TLS:ver<0.7.5>
===> Testing: Cro::HTTP:ver<0.7.5>
Testing with plugin: Zef::Service::Shell::prove+{<anon|1>}
t/http-auth-basic.t ............ ok
t/http-auth-webtoken-bearer.t .. ok
t/http-auth-webtoken-cookie.t .. ok
t/http-client.t ................ ok
t/http-cookie.t ................ ok
t/http-cookiejar.t ............. ok
t/http-log-file.t .............. ok
t/http-middleware.t ............ ok
t/http-request-parser.t ........ ok
t/http-request-serializer.t .... ok
t/http-request.t ............... ok
t/http-response-parser.t ....... ok
t/http-response-serializer.t ... ok
t/http-response.t .............. ok
t/http-router.t ................ ok
t/http-server.t ................ ok
t/http-session-inmemory.t ...... ok
t/http-session-persistent.t .... ok
t/http2-frame-parser.t ......... ok
t/http2-frame-serializer.t ..... ok
t/http2-frame.t ................ ok
t/http2-push-promise.t ......... ok
t/http2-request-parser.t ....... ok
t/http2-request-serializer.t ... ok
t/http2-response-parser.t ...... ok
t/http2-response-serializer.t .. ok
t/http2.t ...................... ok
t/router-auth.t ................ ok
t/uri-http.t ................... ok
All tests successful.
Files=29, Tests=1494, 179 wallclock secs ( 0.28 usr 0.03 sys + 157.66 cusr 10.20 csys = 168.17 CPU)
Result: PASS
===> Testing [OK] for Cro::HTTP:ver<0.7.5>
===> Testing: Cro::WebSocket:ver<0.7.5>
Testing with plugin: Zef::Service::Shell::prove+{<anon|1>}
t/http-router-websocket.t ......... ok
Cannot write to a closed socket
t/websocket-client.t .............. ok
t/websocket-frame-parser.t ........ ok
t/websocket-frame-serializer.t .... ok
t/websocket-handler.t ............. ok
t/websocket-message-parser.t ...... ok
t/websocket-message-serializer.t .. ok
t/websocket-message.t ............. ok
All tests successful.
Files=8, Tests=150, 42 wallclock secs ( 0.05 usr 0.02 sys + 36.62 cusr 2.71 csys = 39.40 CPU)
Result: PASS
===> Testing [OK] for Cro::WebSocket:ver<0.7.5>
===> Testing: cro:ver<0.7.5>
Testing with plugin: Zef::Service::Shell::prove+{<anon|1>}
t/tools-crofile.t ...... ok
t/tools-link-editor.t .. ok
# Check service up attempt 1: Timed out after 10s
# Check service up attempt 2: connection refused
# Check service up attempt 3: Timed out after 10s
# Check service up attempt 1: connection refused
# Check service up attempt 2: connection refused
# Check service up attempt 3: Timed out after 10s
t/tools-runner.t ....... ok
# Couldn't parse YAML
Cannot look up attributes in a Cro::Tools::CroFile type object
in method id at /home/zoffix/.zef/store/cro-0.7.5.tar.gz/cro-0.7.5/lib/Cro/Tools/CroFile.pm6 (Cro::Tools::CroFile) line 28
in block <unit> at t/tools-services.t line 58
t/tools-services.t .....
Dubious, test returned 1 (wstat 256, 0x100)
All 9 subtests passed
Test Summary Report
-------------------
t/tools-services.t (Wstat: 256 Tests: 9 Failed: 0)
Non-zero exit status: 1
Parse errors: No plan found in TAP output
Files=4, Tests=111, 60 wallclock secs ( 0.04 usr 0.01 sys + 36.97 cusr 2.48 csys = 39.50 CPU)
Result: FAIL
===> Testing [FAIL]: cro:ver<0.7.5>
Aborting due to test failure: cro:ver<0.7.5> (use --force-test to override)
in code at /home/zoffix/rakudo/install/share/perl6/site/sources/7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 375
in method test at /home/zoffix/rakudo/install/share/perl6/site/sources/7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 355
in code at /home/zoffix/rakudo/install/share/perl6/site/sources/7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 531
in sub at /home/zoffix/rakudo/install/share/perl6/site/sources/7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 528
in method install at /home/zoffix/rakudo/install/share/perl6/site/sources/7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 623
in sub MAIN at /home/zoffix/rakudo/install/share/perl6/site/sources/E4784A2A0FA00D16808817186E95FE74BEF3FE2D (Zef::CLI) line 152
in block <unit> at /home/zoffix/rakudo/install/share/perl6/site/resources/3065D08F5332CA244672D7F8A05B603F92BB8A7D line 3
in sub MAIN at /home/zoffix/rakudo/install/share/perl6/site/bin/zef line 2
in block <unit> at /home/zoffix/rakudo/install/share/perl6/site/bin/zef line 2
I may be doing this wrong, but I tried using cro stub
to get something running, and cro run
then fails, in two different ways:
Using the most defaults possible, I get an error in sub check
of IO::Socket::Async::SSL
:
kai@taipeihack:~/github/hellocro$ rm -rf hello
kai@taipeihack:~/github/hellocro$ cro stub http hello hello
Stubbing a HTTP Service 'hello' in 'hello'...
First, please provide a little more information.
Secure (HTTPS) (yes/no) [yes]:
Support HTTP/1.1 (yes/no) [yes]:
Support HTTP/2.0 (yes/no) [yes]:
Support Web Sockets (yes/no) [no]:
kai@taipeihack:~/github/hellocro$ HELLO_HOST=localhost HELLO_PORT=10000 cro run
▶ Starting hello (hello)
📓 hello Listening at https://localhost:10000
^Z
[1]+ Stopped HELLO_HOST=localhost HELLO_PORT=10000 cro run
kai@taipeihack:~/github/hellocro$ bg
[1]+ HELLO_HOST=localhost HELLO_PORT=10000 cro run &
kai@taipeihack:~/github/hellocro$ curl -m5 https://localhost:10000
⚠ hello error:00000001:lib(0):func(0):reason(1)
⚠ hello in sub check at /opt/rakudo-star-2017.07/share/perl6/site/sources/7F35A0DCF0EB61FFAE03FF479C6936141F4E9AA6 (IO::Socket::Async::SSL) line 519
⚠ hello in method handle-buffers at /opt/rakudo-star-2017.07/share/perl6/site/sources/7F35A0DCF0EB61FFAE03FF479C6936141F4E9AA6 (IO::Socket::Async::SSL) line 387
⚠ hello in block at /opt/rakudo-star-2017.07/share/perl6/site/sources/7F35A0DCF0EB61FFAE03FF479C6936141F4E9AA6 (IO::Socket::Async::SSL) line 142
⚠ hello
curl: (28) Operation timed out after 0 milliseconds with 0 out of 0 bytes received
kai@taipeihack:~/github/hellocro$ fg
HELLO_HOST=localhost HELLO_PORT=10000 cro run
^CShutting down...
kai@taipeihack:~/github/hellocro$
kai@taipeihack:~/github/hellocro$
If I try specifying no HTTPS, error is no peer-host
method in 'IO::Socket::Async'
:
kai@taipeihack:~/github/hellocro$ rm -rf hello
kai@taipeihack:~/github/hellocro$ cro stub http hello hello ':!secure'
Stubbing a HTTP Service 'hello' in 'hello'...
kai@taipeihack:~/github/hellocro$ HELLO_HOST=localhost HELLO_PORT=10000 cro run
▶ Starting hello (hello)
📓 hello Listening at http://localhost:10000
^Z
[1]+ Stopped HELLO_HOST=localhost HELLO_PORT=10000 cro run
kai@taipeihack:~/github/hellocro$ bg
[1]+ HELLO_HOST=localhost HELLO_PORT=10000 cro run &
kai@taipeihack:~/github/hellocro$ curl -m5 http://localhost:10000
⚠ hello No such method 'peer-host' for invocant of type 'IO::Socket::Async'
⚠ hello in block at /opt/rakudo-star-2017.07/share/perl6/site/sources/DEF16A4E9B3EBA6B6982963C2BDC23DFC6413661 (Cro::HTTP::Log::File) line 26
⚠ hello in block at /opt/rakudo-star-2017.07/share/perl6/site/sources/88931D797A7005CE2FD56A6EF6A37BBD2E8D6CFA (Cro::HTTP::Internal) line 45
⚠ hello in block at /opt/rakudo-star-2017.07/share/perl6/site/sources/1DC86B9F9A31CA5BEE35765E177159BAEDB91AAA (Cro::HTTP::Router) line 82
⚠ hello
curl: (28) Operation timed out after 5001 milliseconds with 0 bytes received
kai@taipeihack:~/github/hellocro$ fg
HELLO_HOST=localhost HELLO_PORT=10000 cro run
^CShutting down...
kai@taipeihack:~/github/hellocro$
This is on Ubuntu:
kai@taipeihack:~/github/hellocro$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
kai@taipeihack:~/github/hellocro$
PS: it might be nice if host and port had default values in case the variables are not set...
Hi All,
I tried to follow the Getting started with Cro guide. The install was fine (other than #75 ) and the hello.p6 example produced the expected result. On the other hand, cro stub http hello hello
failed because cro
is under
/home/david/.rakudobrew/moar-master/install/share/perl6/site/bin
I would assume cro
should, by default, reside under a handy place similar to zef
which is at
/home/david/.rakudobrew/bin/
So should I manually add the needful to PATH or is there any good practice to deal with that under rakudobrew?
Thanks in advance for the help.
This example consumes too much RAM ( without freeing it ) every request and sometimes segfaults.
With MVM_SPESH_DISABLE=1 works fine
ab -c 10 -n 10000 http://127.0.0.1:8888/static/test.txt
#!/usr/bin/env perl6
use v6.c;
use Cro::HTTP::Server;
use Cro::HTTP::Router;
use Cro::HTTP::Request;
my $routes = route {
get -> 'static', *@parts {
# cache-control :public, :max-age(60 * 60); # 1 hour cache for static files
static 'static/', @parts;
}
}
mkdir 'static';
spurt 'static/test.txt', "A" x 1*1024*1024; # 1 MB txt file
my $service = Cro::HTTP::Server.new: :host('0.0.0.0'), :port(8888), :application($routes);
say "Start " ~ $*PROGRAM-NAME;
$service.start();
react whenever signal(SIGINT) { say "GOT KILL INT.....EXIT"; $service.stop; exit }
This is Rakudo version 2018.06-281-g7043559bb built on MoarVM version 2018.06-329-g21ea40f68
implementing Perl 6.c.
Due to the entry in your Cro modules for the perl 6 ecosystem (/path/to/master/branch), any travis build gets the latest commit and any test failures (which are happening now). I have changed one of my modules to track a stable branch (named release) and do dev on the master branch. I have modified my .travis.yml file to test both branches. I have modified the Perl 6 ecosystem entry to track the release branch (/path/to/release/branch). That seems to work well for me.
Due to the probable wide use of your CRO services, I think your customers would be better served.
This should give an overview of all of the links. I'd list them grouped by the service they originate from.
If a service name is provided, it should show two groups of links: links from that service, and then links to that service, if any.
This should be documented in Cro::HTTP::Request
.
macOS 10.13
This is Rakudo version 2018.08 built on MoarVM version 2018.08 (installed with rakudobrew)
t/tools-runner.t fails with the following output:
===> Testing: cro:ver<0.7.6>
# Check service up attempt 1: connection refused
# Check service up attempt 2: connection refused
# Check service up attempt 3: connection refused
# Check service up attempt 4: connection refused
# Check service up attempt 5: connection refused
# Check service up attempt 6: connection refused
# Check service up attempt 7: connection refused
# Check service up attempt 8: connection refused
# Check service up attempt 9: connection refused
# Check service up attempt 10: connection refused
# Check service up attempt 11: connection refused
# Check service up attempt 12: connection refused
# Failed test 'Got response indicating new service running'
# at t/tools-runner.t line 81
# expected: 'Service 1 UPDATED'
# got: 'Service 1 OK'
# Looks like you failed 1 test of 20
Failure is irregular though it passes in about 1 time out of 5-7 attempts.
Created two services and wanted to try the .cro.yml
integration.
dice-bag:
---
name: dice-bag
cro: 1
id: dice-bag
env: []
links: []
entrypoint: service.p6
endpoints:
- id: http
name: HTTP (Insecure)
protocol: http
host-env: DICE_BAG_HOST
port-env: DICE_BAG_PORT
...
monster
---
name: monster
cro: 1
id: monster
env: []
links:
- service: dice-bag
endpoint: http
host-env: DICE_BAG_HOST
port-env: DICE_BAG_PORT
entrypoint: service.p6
endpoints:
- id: http
name: HTTP (Insecure)
protocol: http
host-env: MONSTER_HOST
port-env: MONSTER_PORT
...
Both services live within a parent rpg
folder. (It's where my brain goes). Doing cro run
in this folder I get :
cro run
▶ Starting dice-bag (dice-bag)
🔌 Endpoint HTTP (Insecure) will be at http://localhost:20000/
▶ Starting monster (monster)
🔌 Endpoint HTTP (Insecure) will be at http://localhost:20000/
📓 monster Listening at http://localhost:20000
⚠ dice-bag address already in use
📓 dice-bag Listening at http://localhost:20000
Looking at it I think it's a logic issue in lib/Cro/Tools/Runner.pm6
in assign-ports
. If I'm reading it correctly it attempts to connect to localhost on port 20000. If that manages to connect it increments the count and tries again (up to 60000). If it fails it assumes the port is free and returns the number. But it's not incrementing it in this case. As it's not starting the service the port is being assigned to the next service gets the same port and so on.
I'll look at doing a PR fix for it later but I've got plans for tonight.
Can't seem to get it yet:
zef install --/test cro
===> Searching for: cro
===> Updated cpan mirror: https://raw.githubusercontent.com/ugexe/Perl6-ecosystems/master/cpan.json
===> Updated p6c mirror: http://ecosystem-api.p6c.org/projects.json
===> Searching for missing dependencies: IO::Socket::Async::SSL, JSON::Fast, META6, Shell::Command, File::Find, Terminal::ANSIColor, OO::Monitors, YAMLish
===> Searching for missing dependencies: OpenSSL, Test::META, JSON::Class, MIME::Base64, File::Which
===> Searching for missing dependencies: JSON::Marshal, JSON::Unmarshal
===> Searching for missing dependencies: JSON::Name
===> Installing: OpenSSL:ver('0.1.14'):auth('github:sergot')
===> Installing: JSON::Fast:ver('0.9.2')
===> Installing: JSON::Name:ver('0.0.2'):auth('github:jonathanstowe')
===> Installing: JSON::Marshal:ver('0.0.13'):auth('github:jonathanstowe')
===> Installing: JSON::Unmarshal:ver('0.08')
===> Installing: JSON::Class:ver('0.0.9'):auth('github:jonathanstowe')
===> Installing: META6:ver('0.0.17'):auth('github:jonathanstowe')
===> Installing: Test::META:ver('0.0.11'):auth('github:jonathanstowe')
===> Installing: IO::Socket::Async::SSL:ver('0.2')
===> Installing: File::Which
===> Installing: File::Find:ver('0.1')
===> Installing: Shell::Command
===> Installing: Terminal::ANSIColor:ver('0.3')
===> Installing: OO::Monitors:ver('1.1')
===> Installing: MIME::Base64:ver('1.2'):auth('github:retupmoca')
===> Installing: YAMLish:ver('0.0.3'):auth('Leon Timmermans')
===> Installing: cro:ver('0.7')
===> Install [FAIL] for cro:ver('0.7'): ===SORRY!===
Could not find Cro::HTTP::Router at line 1 in:
/home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site
/home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/vendor
/home/zakame/.rakudobrew/moar-2017.08/install/share/perl6
CompUnit::Repository::AbsolutePath<35596080>
CompUnit::Repository::NQP<55540136>
CompUnit::Repository::Perl5<55540176>
===SORRY!===
Could not find Cro::HTTP::Router at line 1 in:
/home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site
/home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/vendor
/home/zakame/.rakudobrew/moar-2017.08/install/share/perl6
CompUnit::Repository::AbsolutePath<35596080>
CompUnit::Repository::NQP<55540136>
CompUnit::Repository::Perl5<55540176>
in any at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/precomp/1049D337DEF3307152AD072D6367A639E427DB18.1503761556.40112/A5/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 line 1
in block at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/sources/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 (Zef::Client) line 581
in any at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/precomp/1049D337DEF3307152AD072D6367A639E427DB18.1503761556.40112/A5/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 line 1
in block at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/sources/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 (Zef::Client) line 589
in block at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/sources/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 (Zef::Client) line 552
in sub at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/sources/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 (Zef::Client) line 541
in method install at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/sources/A5C13EF833A22B1E85E78D1CD88BE1B0B0B24DA1 (Zef::Client) line 633
in sub MAIN at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/sources/31FF9E8498781BF95868DF98AD861FCF1211BCC1 (Zef::CLI) line 152
in block <unit> at /home/zakame/.rakudobrew/moar-2017.08/install/share/perl6/site/resources/0031ECC6124802A80F7B7B073C50D0A1694E3020 line 1
in sub MAIN at /home/zakame/.rakudobrew/bin/../moar-2017.08/install/share/perl6/site/bin/zef line 2
in block <unit> at /home/zakame/.rakudobrew/bin/../moar-2017.08/install/share/perl6/site/bin/zef line 2
This should produce a summary output of the services that exist, and their basic information: ID, name, and a list of the endpoints. Something like (with stuff in square brackets to be substituted in):
[id] ([Name])
[path]
🔌 Endpoint [id] ([Name])
Host environment variable: [host-env]
Port environment variable: [port-env]
[id] ([Name])
[path]
🔌 Endpoint [id] ([Name])
Host environment variable: [host-env]
Port environment variable: [port-env]
I'd try bold on the top line with id/name, and then grey or similar for the path to deemphasize it a bit. Can show it relative to the current directory, to keep things short/neat.
I don’t see that the server provides CGI environment variables. Are they planned or would a PR for them be considered?
I’m looking at using the cro services to test my CGI module—so far it’s working great! I haven’t yet figured out how to add new code inside a route handler but I’m sure there’s a way.
Can a route pass a hash back in a response? If so, the Cro::HTTP[S]::Server could emulate a CGI server by returning the standard CGI [with TLS extensions] %*ENV hash with known values for testing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.